Q:

How do I use CollectionViewSource to sort xml records by date?

I have the following XML:
<Memories>
<Memory Title="blah blah" ID="1">
  <ImageFile>Data/Images/01.jpg</ImageFile>
  <Blurb>We did blah</Blurb>
  <Date>06/11/2009</Date>
</Memory>
<Memory Title="Graduation" ID="2">
  <ImageFile>Data/Images/02.jpg</ImageFile>
  <Blurb>We graduated!</Blurb>
  <Date>29/11/2007</Date>
</Memory>
<Memory Title="Ski time!" ID="3">
  <ImageFile>Data/Images/03.jpg</ImageFile>
  <Blurb>Ski!!!!!</Blurb>
  <Date>19/12/2008</Date>
</Memory>
//...etc
</Memories>

And the following XAML:
    <CollectionViewSource x:Key="dataCvs" Source="{StaticResource data}" >
        <CollectionViewSource.SortDescriptions >
            <scm:SortDescription PropertyName="Date" />
        </CollectionViewSource.SortDescriptions>
        <CollectionViewSource.GroupDescriptions >
            <dat:PropertyGroupDescription PropertyName="@Name" />
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

I'd like to be able to sort by date, but in its current form, the dates won't sort in natural date order; 06/11/2009 is being sorted as being before 19/12/2008 as one would expect with a program. Changing my date format to yyyy/mm/dd would cause me a problem as the XML date is being displayed as part of my form and it needs to be displayed as dd/mm/yyyy. Can anyone please enlighten me as to how I can sort the dates so suit the display requirements?
Many thanks, I would appreciate any help.

A:

I suspect that this may simply be a major downside to working with pure XML, instead of converting them to business objects.  Raw string values only know how to sort alphanumerically.
If you're willing to solve the problem with some code-behind, you can use the ListCollectionView.CustomSort property, with a custom sorter that will convert strings into a proper DateTime object for sorting.
public class DateStringComparer : IComparer
{
    public int Compare(object x, object y)
    {
        return DateTime.Compare(DateTime.Parse(x.ToString()), DateTime.Parse(y.ToString()));
    }
}

