WPF初学者在这里。
我设法使用本文末尾显示的代码将 TreeView 控件绑定到 DataViewManager。最初填充 TreeView 控件时一切正常,但我想实现两种方式绑定,以便我可以使用文本框过滤掉不需要的 TreeView 项目。我的问题是,如果我尝试使用这样的东西,树视图不会更新:
private void SearchTree_TextChanged(object sender, TextChangedEventArgs e)
{
if(SearchTree.Text.Length>0)
Command.dvm.DataViewSettings["Categories"].RowFilter = "CategoryName LIKE '%"+SearchTree.Text+"%'";
}
谁能帮我找出我在这里做错了什么?!
xml:
...
<UserControl.Resources>
<ObjectDataProvider
x:Key="dataVMProvider"
MethodName="CreateDataVM"
ObjectType="{x:Type local:DataVMCreator}"
/>
<DataTemplate x:Key="InstancesTemplate">
<TextBlock Text="{Binding InstanceUID}"/>
</DataTemplate>
<HierarchicalDataTemplate
x:Key="SymbolsTemplate"
ItemsSource="{Binding Symbols2Instances}"
ItemTemplate="{StaticResource InstancesTemplate}"
>
<TextBlock Text="{Binding SymbolName}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
x:Key="FamiliesTemplate"
ItemsSource="{Binding Families2Symbols}"
ItemTemplate="{StaticResource SymbolsTemplate}"
>
<TextBlock Text="{Binding FamilyName}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
x:Key="CategoriesTemplate"
ItemsSource="{Binding Categories2Families}"
ItemTemplate="{StaticResource FamiliesTemplate}"
>
<TextBlock Text="{Binding CategoryName}"/>
</HierarchicalDataTemplate>
</UserControl.Resources>
...
<TreeView
x:Name="ElementsTree"
...
DataContext="{StaticResource dataVMProvider}"
ItemsSource="{Binding Categories}"
ItemTemplate="{StaticResource CategoriesTemplate}"
/>
DataViewManager 来自:
public static class DataVMCreator
{
public static DataViewManager CreateDataVM()
{
return Command.dvm;
}
}