I have a ObserverableCollection
in my WPF application and I would like to sort it according to a property.
Consider:
var MyCollection = new ObserverableCollection<MyViewModel>;
where MyViewModel
have a property SortOrder
that returns an integer that represent its position in the collection. The integer will not necessary start with 1 or increment by 1 for each object.
I can physical move the objects around on a wpf Canvas (like folders and icons on the desktop) and the SortOrder depends on the position. So when I move an object I need to update its position in the collection.
I also need to add objects to the collection, so how can I do that while ensuring that the objects are ordered according to SortOrder
?
The collection will typically contain between 1-30 items.