Posted 4 October 2017, 7:31 am EST
Here are a couple of alternatives. You could shorten my code above to:
grid.ItemsSource = Customer.GetCustomerList(100);
grid.AllowSorting = true;
((C1CollectionView<object>)(grid.CollectionView)).SortChanged += GridSortChanged;
You could also use the following extension methods:
public static void AttachSortChanged<T>(this ICollectionView<T> collectionView, EventHandler handler) where T : class
{
(collectionView as ISupportSorting).SortChanged += handler;
}
/// <summary>
/// Dettaches the specified handler from the sort changed event.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collectionView">The collection view.</param>
/// <param name="handler">The event handler.</param>
public static void DettachSortChanged<T>(this ICollectionView<T> collectionView, EventHandler handler) where T : class
{
(collectionView as ISupportSorting).SortChanged -= handler;
}
And then use code like the following to attach it:
grid.ItemsSource = Customer.GetCustomerList(100);
grid.AllowSorting = true;
grid.CollectionView.AttachSortChanged(GridSortChanged);