【发布时间】:2011-08-09 00:47:46
【问题描述】:
我有一个绑定到TreeView 的Layers 列表,其中每个实例都有一个Effects 列表。我通过 HierarchicalDataTemplate 展示它们,效果很好,但我正在尝试使用 SortDescriptions 对它们进行排序。
我不知道如何在 xaml 中执行此操作,但这样做只会对第一级项目进行排序,而不是子项目:
ICollectionView view = CollectionViewSource.GetDefaultView ( treeView1.ItemsSource );
view.SortDescriptions.Add ( new SortDescription ( "Name", ListSortDirection.Ascending ) );
我尝试先按.Color 对它们进行排序,然后按.Name。
有什么想法吗?
编辑:我添加了这段代码:
<Window.Resources>
<CollectionViewSource x:Key="SortedLayers" Source="{Binding AllLayers}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Color" />
<scm:SortDescription PropertyName="Name" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Window.Resources>
但这仍然只适用于第一级层次结构。如何为每个 layer.Effects 集合指定它?
【问题讨论】: