I'm having troubles doing filtering on a WPF TreeView.
Here is my TreeView XAML:
<TreeView x:Name="ResourcesTreeView" ItemsSource="{Binding Path=FilteredResources}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type models:HierarchicalResource}" ItemsSource="{Binding ContainedResources}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ResourceIdentifier.ResourceType, Converter={StaticResource ResourceTypeToIconConverter}}"
Stretch="Uniform" Height="23" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Path=Name}" Style="{StaticResource ResourceName}" VerticalAlignment="Center"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction Command="{Binding OnSelectedResourceChangedCommand}"
CommandParameter="{Binding ElementName=ResourcesTreeView, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
Here is the HierarchicalResource class:
public class HierarchicalResource
{
public HierarchicalResource(ResourceIdentifier resourceIdentifier, List<HierarchicalResource> containedResources, string name)
{
this.ResourceIdentifier = resourceIdentifier;
this.ContainedResources = containedResources;
this.Name = name;
}
public ResourceIdentifier ResourceIdentifier { get; }
public List<HierarchicalResource> ContainedResources { get; set; }
public string Name { get; }
}
This is how Im initializing the CollectionViewProperty:
this.FilteredResources = CollectionViewSource.GetDefaultView(resourcesTree);
the resourcesTree is a list that contain one root element, that contain several children in its ContainedResources property. It works an looks great. Only problem is that when trying to filter it is not working. When I am trying to use this.FilteredResources.Filter = obj => { ... } it is happening only once on the root node. How can I really make the Filter delegate to be executed on each of the existing tree nodes??
Thanks, Guy