Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Filtering XamDataTree with ReactiveUI
posted

While trying to replace a TreeView with a XamDataTree I experience problems when clearing an applied filter. The first code snippets shows the working version using a TreeView.

  <TreeView Grid.Column="0" Grid.Row="1"
                              ItemsSource="{Binding TrendGroupViewModels}"
                              DataContext="{Binding TrendGroups }"
                              VirtualizingStackPanel.IsVirtualizing="True"
                              VirtualizingStackPanel.VirtualizationMode="Recycling">
                        <TreeView.Resources>
                            <Style TargetType="{x:Type TreeViewItem}">
                                <Setter Property="IsExpanded"
                                        Value="{Binding IsExpanded,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
                                <Setter Property="IsSelected"
                                        Value="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
                            </Style>

                            <HierarchicalDataTemplate DataType="{x:Type viewModels:TrendGroupViewModel}"
                                                      ItemsSource="{Binding Inferiors}">

The TreeView code has been replaced with the following XamDataTree code.

 <ig:XamDataTree
    IsExpandedMemberPath="IsExpanded"
    IsSelectedMemberPath="IsSelected"
    ItemsSource="{Binding TrendGroupViewModels}"
    DataContext="{Binding TrendGroups }"

    VirtualizingStackPanel.IsVirtualizing="True"
    VirtualizingStackPanel.VirtualizationMode="Recycling"

    <ig:XamDataTree.GlobalNodeLayouts>
        <ig:NodeLayout
            TargetTypeName="IAkzGroupTreeViewModel"
            DisplayMemberPath="TypeName"
            Key="Inferiors" />
        </ig:XamDataTree.GlobalNodeLayouts>

Each node is provided with a BehaviorSubject that filters the nodes children when

_filter.OnNext(node => additonalNodes.Contains(id));

 is called.

BehaviorSubject<Func<Node<ITreeItemDto, Guid>, bool>> _subFilter =
            new BehaviorSubject<Func<Node<ITreeItemDto, Guid>, bool>>(node => true);

The initial lazy loading as well as first filter action work as expected. When the tree is partially unfolded, clearing the filter does not show the initial tree as expected. Filtered node siblings of unfolded nodes do not reload/refresh their children.

Secondly search results (nodes) are duplicated when expanded to before filtered sibling nodes.