0

好的,我有一个ItemsControl绑定到 aList<IComparableObject>的对象,每一秒List对象都会改变,所以我必须使用它们,所以每一秒我都会调用该List.Sort()方法。在 VS2008 中的 Watch 面板中检查,我可以知道List得到了排序,但ItemsControl没有。我怎样才能使这项工作?

谢谢!

4

1 回答 1

5

您必须对 CollectionView 进行排序:

 List<MyObject> myInternalList = new List<MyObject>();
 ...
 ICollectionView colView = CollectionViewSource.GetDefaultView(myInternalList);
 colView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

您必须从列表中获取默认视图。在这种情况下,您不必对列表进行排序,因为视图将始终被排序。您可以添加任意数量的 SortDescriptions。

高温高压

于 2009-08-07T08:56:57.677 回答