原文轉載自慧都控件網:http://www.evget.com/zh-CN/Info/catalog/18220.html
在Mindscape WPF Elements中時如何實現排序、過濾和分組的呢,今天就來分享一下:
網格排序
網格屬性可以按照以下方式來進行設置:
通過設置一個合適的IComparer排序屬性:
<ms:PropertyGrid Sorting='{x:Static ms:PropertySorting.ByHumanName}'/>
通過設置的BindingView屬性默認視圖的CustomSort屬性。
通過應用SortDescription到BindingView屬性的默認視圖,如下:
屬性網格排序(程序):
SortDescription alphabetical = new SortDescription("Node.HumanName", ListSortDirection.Ascending);
ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
view.SortDescriptions.Add(alphabetical);
如果網格的一個實例包含擴展節點,排序描述不傳播到子節點(但自定義排序會),如果使用的是SortDescriptions來進行子節點排序,
在BindingView collection中定位父節點,並應用一個SortDescription到子屬性的默認視圖。
過濾網格條目
網格屬性可以通過設置BindingView屬性的默認視圖的過濾屬性來過濾,如下所示:
ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
view.Filter = delegate(object obj)
{
Node node = ((PropertyGridRow)obj).Node;
return node.Children.Count == 0;
};
分組網格
屬性可以按照下面的方法來進行分組:
通過設置分組屬性到一個合適的GroupDescription,分組屬性包含了一個預定義的對於按情況分組的GroupDescription。
分組屬性(聲明):
<ms:PropertyGrid Grouping='{x:Static ms:PropertyGrouping.ByCategory}'/>
通過應用一個GroupDescription到綁定窗口屬性的默認視圖,如下所示:
分組屬性(程序):
PropertyGroupDescription byCategory = new PropertyGroupDescription("Node", new NodeToCategoryConverter());
ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView);
view.GroupDescriptions.Add(byCategory);
內置支持
屬性網格控件選擇性的用命令顯示工具欄,比如對於按字母順序排序,或按照類別分組(使用CategoryAttribute),或是搜索過濾設備