I'm using a TreeView and the HierarchicalDataTemplate to show some data. Sometimes the quantity of this data is quite much, so I would like to implement a button, which collapses the TreeView completely and another button, which expands it.
My XAML of the TreeView looks like this for now:
<TreeView x:Name="constOutput" Margin="25,96,25,229" SelectedItemChanged="ConstOutput_SelectedItemChanged" ItemsSource="{Binding FoundConstants}">
<TreeView.Resources>
<Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
<HierarchicalDataTemplate DataType="{x:Type local:Constant}" ItemsSource="{Binding Children}">
<WrapPanel HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=SrcFile.Name, StringFormat='({0})'}" Foreground="#006666" FontSize="13" HorizontalAlignment="Right" Margin="10, 2, 0, 0"/>
<TextBlock Text="{Binding Path=Children.Count, StringFormat='[{0}]'}" FontSize="13" HorizontalAlignment="Right" Margin="10, 2, 0, 0"/>
</WrapPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Constant}" ItemsSource="{Binding Children}">
<WrapPanel>
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=SrcFile.Name, StringFormat='({0})'}" Foreground="#006666" FontSize="13" Margin="10, 2, 0, 0"/>
<TextBlock Text="{Binding Path=Children.Count, StringFormat='[{0}]'}" FontSize="13" HorizontalAlignment="Right" Margin="10, 2, 0, 0"/>
</WrapPanel>
<HierarchicalDataTemplate.ItemTemplate>
Im also using a ControlTemplate for the TreeView.
I think, I need to loop through all the elements of the TreeView and set all of the nodes on IsExpanded=false. I just don't know, where I would set it.