A data view has been set for the TreeView. It looks like this (some fields are removed for clarity):
<HierarchicalDataTemplate x:Key="TreeTemplate" ItemsSource="{Binding Mode=TwoWay,Path=Vars}"> <Border BorderBrush="#FFCBBEBE" BorderThickness="1" Padding="0,2,0,1"> <WrapPanel Margin="0,1,0,2"> <TextBlock Text="{Binding Mode=TwoWay, Path=Name, UpdateSourceTrigger=PropertyChanged}" Margin="5,0" FontSize="18" Width="900"/> </WrapPanel> </Border> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <Border BorderBrush="#FFCBBEBE" BorderThickness="1" Padding="0,2,0,1" Visibility="{Binding Path=Visible}"> <WrapPanel Margin="0,1,0,2"> <TextBlock Width="350" Height="30" Margin="5,0" Text="{Binding Mode=TwoWay, Path=Name, UpdateSourceTrigger=PropertyChanged}" FontSize="18"></TextBlock> </WrapPanel> </Border> </DataTemplate> </HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate>
As can be seen from the code and the picture, the tree has two levels. Root elements are bound to the Name property of the data source. Nested elements also have the Name property and some others that I did not show here. The problem is that the visibility of the nested element must also be picked up from the data source. In the example, I showed the visibility of the Border element, but there is still empty space at the place of the deleted elements, as shown in the figure. How to specify the visibility of the TreeViewItem itself?
TreeViewItem
, you haveIsExpanded
. Tell me better what you want to achieve; maybe aTreeView
is an inappropriate tool. - VladDItemsSource
and that's it. Work at the ViewModel level. - VladD