Ok, I have an ItemsControl
binded to a List<IComparableObject>
, each second the List
objects change, so I have to resort them, so each second I call the List.Sort()
method. Checking in the Watch panel in VS2008, I can tell the List
gets sorted, but the ItemsControl
doesn't. How can I make this work?
Thanks!
You have to sort the CollectionView:
List<MyObject> myInternalList = new List<MyObject>();
...
ICollectionView colView = CollectionViewSource.GetDefaultView(myInternalList);
colView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
You have to get the default view from the List. In this case, you don't have to sort the List, because the view will always be sorted. You can add as many SortDescriptions you want.
HTH