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> 

Sample

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?

  • For TreeViewItem , you have IsExpanded . Tell me better what you want to achieve; maybe a TreeView is an inappropriate tool. - VladD
  • You need to control the visibility of the item highlighted in red. In the figure, the element located between the element “Blow Temperature” and “Cold Blow Temperature” is deactivated. Since now I control the visibility not of the TreeViewItem, but Border, a white stripe formed in its place. IsExpanded can hide all child elements, and I control the visibility of each element. Therefore, it does not fit. - maestro
  • But even if I use IsExpanded, I do not know how to access it. The situation is similar to that described. UPD. That is, you need to transfer Visibility = "{Binding Path = Visible}" from the Boder element to the TreeViewItem. - maestro
  • 2
    @Alouette: Why do you need to control visibility at the View level? It is not right. You just should not have this item in ItemsSource and that's it. Work at the ViewModel level. - VladD
  • Such a technical task. It is necessary to control the visibility of all parameters both when displayed on the form and in the report. And you should not delete an item from ItemsSource, since each parameter participates in the calculation. - maestro

0