title: Binding multiple level hierarchy data in treeview wpf
body: <p>i need to bind recursive child nodes for a treeview in wpf .But i really dunno how to make it work .Here is what i have found</p>
  
  <pre><code>ObservableCollection&lt;Animal&gt; animals = new ObservableCollection&lt;Animal&gt;();
  animals.Add(new Animal("California Newt"));
  animals.Add(new Animal("Tomato Frog"));
  animals.Add(new Animal("Green Tree Frog"));
  animals.Add(new Animal("Frog"));
  AnimalCategories.Add(new AnimalCategory("Amphibians", animals));
  
  animals = new ObservableCollection&lt;Animal&gt;();
  animals.Add(new Animal("Golden Silk Spider"));
  animals.Add(new Animal("Black Widow Spider"));
  AnimalCategories.Add(new AnimalCategory("Spiders", animals))
  </code></pre>
  
  <p>List that need to be binded on the treeview and here is the structure for it</p>
  
  <p>AnimalCategory Class:</p>
  
  <pre><code>Class AnimalCategory 
      Private _category As String
      Public Property Category As String
          Get
              Return _category
          End Get
          Set(ByVal value As String)
              _category = value
          End Set
      End Property
      Private _animals As ObservableCollection(Of Animal)
      Public ReadOnly Property Animals() As ObservableCollection(Of Animal)
          Get
  
              If _animals Is Nothing Then
                  _animals = New ObservableCollection(Of Animal)()
              End If
  
              Return _animals
          End Get
      End Property
  
      Public Sub New()
      End Sub
      Public Sub New(category As String, animals As ObservableCollection(Of Animal))
          _category = category
          _animals = animals
      End Sub
  End Class
  </code></pre>
  
  <p>Animal Class:</p>
  
  <pre><code>Class Animal
      Private _name As String
      Public Property Name As String
          Get
              Return _name
          End Get
          Set(ByVal value As String)
              _name = value
          End Set
  
  
      End Property
      Public Sub New()
      End Sub
      Public Sub New(name As String)
          _name = name
      End Sub
  End Class
  </code></pre>
  
  <p>and my xaml code is..!</p>
  
  <pre><code>&lt;TreeView x:Name="radTreeView"   Background="#4E4E4E" x:FieldModifier="public"  ItemsSource="{x:Static local:cntlWPFMMTreeView.AnimalCategories}"
          ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible"&gt;
  &lt;telerik:RadTreeView.ItemTemplate&gt;
          &lt;HierarchicalDataTemplate ItemsSource="{Binding Animals}"&gt;
              &lt;TextBlock  Text="{Binding Category}" /&gt;
              &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBlock Text="{Binding Name}"/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/telerik:RadTreeView.ItemTemplate&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>Using the above code i can bind one level of parent child hiereachy like below,</p>
  
  <p><a href="https://i.stack.imgur.com/Py4vJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Py4vJ.png" alt="enter image description here"></a></p>
  
  <p>Buit i need to get bind something like many level of hierarchy like below dynamically</p>
  
  <p><a href="https://i.stack.imgur.com/O2H2N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O2H2N.png" alt="enter image description here"></a></p>
  
  <p>How to do it in WPF ..? </p>