Ever Need a Sortable ObservableCollection?
Recently I had a ListBox bound to an ObservableCollection. The powers that be wanted me to sort the items in the collection in alphabetical order. Much to my surprise I found that this was not something built into a ListBox or into the ObservableCollection. So, I set out to figure out how to do this in WPF. I found a very cool posting on the Internet where this programmer (I’ll have to find his name and post it to give him credit) that showed me how to make a new class called SortableObservableCollection that extends the ObservableCollection but also adds functionality to sort it. So, I built and it worked great. So, I am sharing my code with you. You can download my sample application here:
You can either just add the reference assembly (found in the Debug/Bin folder of the zip) or you can just create a new class called SortableObservableCollection and copy the code from my class with the same name.