1
votes

I have a WPF TreeView with a HierarchicalDataTemplate. As I descend the hierarchy, expanding the nodes, I will eventually get to the bottom and data displayed via a normal DataTemplate. I'd like not to show those nodes - if I set the DataTemplate's containing TextBlock to Visible Hidden (or similar) I just get allocated space in the treeview. I'd like not to display those items so assume I need to remove them somehow. I cannot use a Filter on a CollectionView as there may be other nodes with children at this level. So basically, at any level I want to remove those nodes that have no children. The actual data is being loaded from an Xml file via an XmlDataProvider, so there are no class objects. Can anyone suggest how

thanks John

1

1 Answers

0
votes

Presumably you ask the question because the last nodes in the tree are of the same type so you use only the one HierarchicalDataTemplate:

<HierarchicalDataTemplate DataType="{x:Type src:MyNodeClass}" ItemsSource = "{Binding Path=Items}">
  <TextBlock Text="{Binding Path=PropertyToDisplay}"/>
</HierarchicalDataTemplate>

If you could change the type of your last nodes they will not automatically use the template (you could also inherit from the normal type so the collection allows them even though the new class is actually empty).