I have multiple ObservableCollection<T>
s that are bound to a TreeView
using a HierarchicalDataTemplate
similar to the implementation found in How to mix databound and static levels in a TreeView?.
My problem is one (or more) of the elements in the collections can be null on occasion but they are still displayed in the TreeView as a blank line, such as in this example:
Other than removing them from the collection, is there a method to hiding these elements so they will not appear in the User Interface until they are changed to a non-null value?
If the structure of the XAML is relavant, this is roughly what I am doing:
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:FolderNode}"
ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Path=DisplayName}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:ParentItem}">
<HierarchicalDataTemplate.ItemsSource>
<MultiBinding>
<MultiBinding.Converter>
<local:MultiCollectionConverter />
</MultiBinding.Converter>
<Binding Path="Children1" />
<Binding Path="Children2" />
</MultiBinding>
</HierarchicalDataTemplate.ItemsSource>
<TextBlock Text="{Binding Path=DisplayName}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:ChildItemWithChildCollection}"
ItemsSource="{Binding}">
<TextBlock Text="{Binding Path=DisplayName}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:ChildItemWithChild}"
ItemsSource="{Binding Path=GrandChildren}">
<TextBlock Text="{Binding Path=DisplayName}" FontWeight="Bold" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:GrandChildItem}">
<TextBlock x:Name="Item" Text="{Binding Path=DisplayName}" />
</DataTemplate>
<DataTemplate DataType="{x:Type local:ChildItemWithoutChildCollection}">
<TextBlock Text="{Binding Path=DisplayName}" />
</DataTemplate>
</TreeView.Resources>