0

WPF beginner here.

I managed to bind a TreeView control to a DataViewManager using the code shown at the end of this post. Everything works fine when populating the TreeView control initially but I want to implement two way binding so that I can use a textbox to filter out unwanted TreeView items. My problem is that the treeview isn't updated if I'm trying to use something like this:

        private void SearchTree_TextChanged(object sender, TextChangedEventArgs e)
        {
            if(SearchTree.Text.Length>0)
            Command.dvm.DataViewSettings["Categories"].RowFilter = "CategoryName LIKE '%"+SearchTree.Text+"%'";
        }

Can anyone please help me find out what I'm doing wrong here?!

Xaml:

...
    <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}"
        />

The DataViewManager comes from:

    public static class DataVMCreator
    {
        public static DataViewManager CreateDataVM()
        {
            return Command.dvm;
        }
    } 
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
timur
  • 1

1 Answers1

0

Try this binding for the DataContext of your TreeView:

DataContext="{Binding Source={StaticResource dataVMProvider}}"
Roel van Westerop
  • 1,360
  • 8
  • 17
  • Thanks, but nothing changes... I also tried `DataContext="{Binding ., Mode=TwoWay, Source={StaticResource dataVMProvider}, UpdateSourceTrigger=PropertyChanged}"` with no improvements. – timur Apr 30 '15 at 19:15