The observed collection does not sort for the simple reason that every time an item moves from one place in the list to another, the collection raises an event. It would be great to watch the animation of the sorting algorithm in action, but it kind of sucks, you know, sorting.
There are two ways to do this; they are very similar, and both begin by sorting items outside their observable collection, for example. if _Fruits is an ObservableCollection<Fruit> , and you defined IComparer<Fruit> to sort, you would do:
var sorted = _Fruits.OrderBy(x => x, new FruitComparer());
This creates a new IEnumerable<Fruit> , which, when you iterate over it, will have objects in the new order. There are two things you can do with this.
One of them is to create a new collection, replace the old one and force the elements (elements) of elements in the user interface to reinstall on it:
_Fruits = new ObservableCollection<Fruit>(sorted); OnPropertyChanged("Fruits");
(It is assumed that your class implements INotifyPropertyChanged usual way.)
Another is to create a new sorted list and then use it to move items in your collection:
int i = 0; foreach (Fruit f in sorted) { _Fruits.MoveItem(_Fruits.IndexOf(f), i); i++; }
The second approach is that I will only try if I had a really serious obligation not to reinstall the controls for the elements, because it collects a ton of events related to a collection change.