WPF: Add multiple level with different types items to TreeView
<p>I have a class <code>(ClassA)</code> that contains two different types of lists, <code>List of ClassBTypes</code> and <code>List of ClassC</code>. <code>ClassBTypes</code> has its own <code>List of ClassB</code>.</p>

<p>I want to achieve the below structure for the TreeView</p>

<pre><code>-- ClassAName   
-- -- ClassBType1Name  
-- -- -- ClassB1Name  
-- -- -- ClassB2Name     
-- -- ClassBType2Name  
-- -- -- ClassB1Name  
-- -- -- ClassB2Name  
-- -- ClassC1Name  
-- -- ClassC2Name
</code></pre>

<p>I managed to get the tree to draw the <code>ClassA</code> and <code>ClassB</code>, but couldn't figure out how to add <code>ClassC</code> to the <code>Tree resources</code>.<br>
Please check the below source code.</p>

<p>Test.xaml.cs       </p>

<pre><code>public partial class Test : Window {    
    InitializeComponent();
    var a = new List&lt;ClassA&gt;{new ClassA(), new ClassA()};
    treeView.ItemsSource = a;
}
</code></pre>

<p>C# classes:    </p>

<pre><code>public class ClassA{    
    // initiate obj    
    public string Name {get; set;}     
    public List&lt;ClassBTypes&gt; Btypes {get; set;}     
    public List&lt;ClassC&gt; C {get; set;}    
}    
public class ClassBTypes{    
    public string Name {get; set;}    
    public List&lt;ClassB&gt; B {get; set;}   
}    
public class ClassB{    
    public string Name {get; set;}    
}     
public class ClassC{   
    public string Name {get; set;}   
}  
</code></pre>

<p>xaml code:     </p>

<pre><code>&lt;Window.Resources&gt;
    &lt;DataTemplate x:Key="aKey"&gt;
        &lt;TextBlock Text="{Binding Name}"&gt;&lt;/TextBlock&gt;
    &lt;/DataTemplate&gt;
    &lt;HierarchicalDataTemplate x:Key="bKey"
               ItemsSource="{Binding B}"
               ItemTemplate="{StaticResource aKey}"&gt;
        &lt;TextBlock Text="{Binding Name}" /&gt;
    &lt;/HierarchicalDataTemplate&gt;
    &lt;HierarchicalDataTemplate x:Key="bTypeKey"
               ItemsSource="{Binding Btypes}"
               ItemTemplate="{StaticResource bKey}"&gt;
        &lt;TextBlock Text="{Binding Name}" /&gt;
    &lt;/HierarchicalDataTemplate&gt;
&lt;/Window.Resources&gt;   
.....     
&lt;Grid&gt;
   &lt;TreeView Name="treeView" ItemTemplate="{StaticResource bTypeKey}" /&gt;
&lt;/Grid&gt;
</code></pre>

<p>How to add the <code>ClassC list</code> from <code>ClassA</code> obj, I've added the below code to <code>&lt;Window.Resources&gt;</code> but how can I added it to treeView resources.</p>

<pre><code>&lt;HierarchicalDataTemplate x:Key="bTypeKey"
         ItemsSource="{Binding Btypes}"
         ItemTemplate="{StaticResource bKey}"&gt;
    &lt;TextBlock Text="{Binding Name}" /&gt;
&lt;/HierarchicalDataTemplate&gt;
</code></pre>