好的,我有一个ItemsControl
绑定到 aList<IComparableObject>
的对象,每一秒List
对象都会改变,所以我必须使用它们,所以每一秒我都会调用该List.Sort()
方法。在 VS2008 中的 Watch 面板中检查,我可以知道List
得到了排序,但ItemsControl
没有。我怎样才能使这项工作?
谢谢!
好的,我有一个ItemsControl
绑定到 aList<IComparableObject>
的对象,每一秒List
对象都会改变,所以我必须使用它们,所以每一秒我都会调用该List.Sort()
方法。在 VS2008 中的 Watch 面板中检查,我可以知道List
得到了排序,但ItemsControl
没有。我怎样才能使这项工作?
谢谢!
您必须对 CollectionView 进行排序:
List<MyObject> myInternalList = new List<MyObject>();
...
ICollectionView colView = CollectionViewSource.GetDefaultView(myInternalList);
colView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
您必须从列表中获取默认视图。在这种情况下,您不必对列表进行排序,因为视图将始终被排序。您可以添加任意数量的 SortDescriptions。
高温高压