ClickEventArgs e) { ListCollectionView view = (ListCollectionView)Binding.GetView(persons); if( view.Sort.Length == 0 ) { view.Sort = new SortDescription[] { new SortDescription("Name", ListSortDirection.Ascending), new SortDescription("Age", ListSortDirection.Descending), }; } else { view.Sort = new SortDescription[0]; } view.Refresh(); } 请注意由要进行排序的属性名称和顺序(升序或降序)构建的 SortDescription 对象数组的使用。还要注意对视图对象上的 Refresh 的调用。当前,这要求使用视图的新属性来刷新绑定控件(尽管希望在 Longhorn 的将来的版本中不要求对 Refresh 显式调用)。 SortDescription 对象的数组应该涵盖大多数情况,但是如果想要更多的控件,可以通过实现 IComparer 接口为视图提供自定义排序对象。 void sortButton_Click(object sender, ClickEventArgs e) { ListCollectionView view = (ListCollectionView)Binding.Ge页码:[1] [2] [3] [4] [5] [6] [7] [8] 第6页、共8页 |