0

This code works well

 ICollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource);

            if (dataView != null)
            {
                // Specify the new sorting information.
                dataView.SortDescriptions.Clear();
                var description = new SortDescription(propertyName, _sortDirection);
                dataView.SortDescriptions.Add(description);

                dataView.Refresh();               
            }

and for exaple string type of propery ir sorts alphabetically , and for enum it sorts in base of enum number , question is i want custom comparison for enum.

1 Answer 1

1

What you can do, if you source list implements IList, you can cast you collection view source to ListCollectionView and set ListCollectionView.CustomSort with custom IComparer class where you can implement you custom sorting logic

ListCollectionView dataView = (ListCollectionView)(CollectionViewSource.GetDefaultView(this.ItemsSource));
dataView.CustomSort = new MyCustomSort();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.