Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
SortComparer
posted

Hi,

I am trying to make a custom sort comparer for a XamGrid TextColumn. My XamGrid is binded to an ICollectionView.

I have the following in the xaml:

<comparer:DateTimeStringComparer x:Key="MySortComparer"/>

<ig:TextColumn Key="LastPublished" SortComparer="{StaticResource MySortComparer}">
<ig:TextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="LAST PUBLISHED" />
</DataTemplate>
</ig:TextColumn.HeaderTemplate>
</ig:TextColumn>

Then my comparer:

public class DateTimeStringComparer : IComparer<string>
{
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int Compare(string x, string y)
{

var dateTimeX = Convert.ToDateTime(x);
var dateTimeY = Convert.ToDateTime(y);

var dateTimeXStr = dateTimeX.ToString("s");
var dateTimeYStr = dateTimeY.ToString("s");

return StringComparer.OrdinalIgnoreCase.Compare(dateTimeXStr, dateTimeYStr);
}

}

The SortComparer is not being invoke. I am not sure if it has something to do with what is binded (ICollectionView).