0

I need to sort ObservableCollection without assigning new one to source. Right now I have this:

private void SortingObservableCollection(ObservableCollection<MyObject> toSort)
{
    Items = new ObservableCollection<MyObject>(toSort.OrderBy(x => x.Top).ThenBy(x => x.Left));
}

It almost works perfectly, but I need to do it without assignign new one.

Desired effect is exactly what I could do on a list:

toSort = toSort.OrderBy(x => x.Top).ThenBy(x => x.Left).ToList();
  • 2
    Instead of sorting the ObservableCollection, you might want to use a CollectionViewSource. See [How to: Sort Data in a View](https://learn.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-sort-data-in-a-view). – Clemens Aug 06 '17 at 13:24
  • It seems I cannot upvote comments, so just Thank you both very much! – cantdoanything33 Aug 06 '17 at 13:40

0 Answers0