我有一个功能列表,每个功能都有一个字段列表。
我可以在TreeView
控件的帮助下相应地显示它们。
-Feature1
-FieldMemberA
-FieldMemberB
的 -Feature2
-FieldMemberX
现在我想对功能列表和字段列表进行排序。对功能列表进行排序与CollectionViewSource
一起使用。但是,我无法对 Fields 列表应用相同的内容。
我复制了工作代码:
<UserControl.Resources>
<CollectionViewSource Source="{Binding Features}" x:Key="SortedFeatures">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription Direction="Descending" PropertyName="Prop1"/>
<componentModel:SortDescription Direction="Ascending" PropertyName="Prop2"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid>
<TreeView ItemsSource="{Binding Source={StaticResource SortedFeatures}}">
<TreeView.Resources>
<HierarchicalDataTemplate ItemsSource="{Binding Fields}" DataType="{x:Type model:Feature}">
<RadioButton Name="IsSelectedRadioButton" Content="{Binding Path=FeatureName}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" GroupName="selectedFeatureGroup"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type model:Field}">
<CheckBox Name="CriteriaCheckBox" Content="{Binding Path=FieldName}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" />
</DataTemplate >
</TreeView.Resources>
</TreeView>
</Grid>
我尝试的是:
<CollectionViewSource Source="{Binding Fields}" x:Key="SortedFields">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription Direction="Descending" PropertyName="Prop1"/>
<componentModel:SortDescription Direction="Ascending" PropertyName="Prop2"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
在<TreeView.Resources>
下并绑定到SortedFields
而不是Fields
。