I can't find how to add custom sorting to WPF ListView control? I don't need to sort by columns asc or desc, I need a custom one with some algorithm in it?
can you help me?
Thank you!
You can use CustomSort property on ListCollectionView provided that you implement IComparer for your class:
//somewhere in code behind of your window:
var view = (ListCollectionView)CollectionViewSource.GetDefaultView(Items); //Items is an ObservableCollection<T>
view.CustomSort = new MyComparer(); //MyComparable implements IComparer
Any control bound to your Items such as ListBox will display elements in order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With