WPF ItemsControl数据文本排序 [英] WPF ItemsControl datacontext sorting

查看:754
本文介绍了WPF ItemsControl数据文本排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个 ItemsControl 绑定到一个列表< IComparableObject> ,每秒列表对象改变,所以我必须诉诸他们,所以每一秒我调用$ code> List.Sort()方法。在VS2008中检查Watch面板,我可以告诉列表被排序,但是 ItemsControl 没有。如何使这项工作?

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?

谢谢!

推荐答案

你必须对CollectionView进行排序:

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));

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

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

这篇关于WPF ItemsControl数据文本排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆