Have you ever had to make a TreeView that needed to be populated from an ItemsSource, but where some levels in the tree need to be static which in turn have a dynamic sub lists? It is possible, but not so easy. These are 2 helper classes tha make this task a lot easier. Here's a small example:
<Window.Resources>
<DataTemplate DataType="{x:Type v:TreeItemObject}"> <TextBlock Text="{Binding Path=ItemsSourcePath}"/> DataTemplate>
<HierarchicalDataTemplate x:Key="PropertiesTreeItemObject"
ItemsSource="{Binding Path=Properties}"/>
<HierarchicalDataTemplate x:Key="FieldsItemObject"
ItemsSource="{Binding Path=Fields}"/>
<v:TreeItemObjectTemplateSelector x:Key="Selector"/>
<col:ArrayList x:Key="StaticItems">
<v:TreeItemObject ItemsSourcePath="Properties"/>
<v:TreeItemObject ItemsSourcePath="Fields"/>
col:ArrayList>
<HierarchicalDataTemplate DataType="{x:Type Class}" ItemsSource="{Binding Source={StaticResource StaticItems}}" ItemTemplateSelector="{StaticResource Selector}"> <TextBlock Text="{Binding Path=Name}"/> HierarchicalDataTemplate>
Window.Resources>
<TreeView ItemsSource="{Binding Path=Classes}"/>