I have an ObservableCollection binding on a WPF list view. I am looking to be able to sort the columns of a ListView control by clicking on the column heading. To do this, I sort the ObservableCollection and let the binding take care of updating the GUI.
To sort the ObservableCollection, I use the following code:
sortedData = new ObservableCollection<Tag>( from x in data
orderby x.ID descending
select x );
data = sortedData;
NB: data bound to ListView
The problem I am facing is that for each column there will be a lot of copy-paste code to achieve the desired effect. Is it possible to pass part of orderby x.ID in descending order to the LINQ operator as a function parameter?
Or is there an easier way to achieve the desired result?