title: wpf TreeView HierarchicalDataTemplate related
body: <p>I have a question related to HierarchicalDataTemplate. Is it possible to keep adding HierarchicalDataTemplate via code or there is no way to do that. I'm asking this because in my case later i don't know if i will need more child nodes than these i have now.</p>
  
  <p>below you can see my treeview:</p>
  
  <pre><code>&lt;TreeView Background="#FFF0F0F0" BorderBrush="#FFE5E2DB" IsEnabled="{Binding isAllesEnabled}" ItemsSource="{Binding LijstRechten, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" Margin="0,0,0,0" Name="dgStamOverzichtGebruikerRechten" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"&gt;
      &lt;TreeView.ItemTemplate&gt;
          &lt;!-- Top Level --&gt;
          &lt;HierarchicalDataTemplate ItemsSource="{Binding Childs}"&gt;
              &lt;CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" /&gt;
  
              &lt;!-- 1st Child Level --&gt;
              &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;HierarchicalDataTemplate ItemsSource="{Binding Childs}"&gt;
                      &lt;CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" /&gt;
  
                      &lt;!-- 2nd Child Level --&gt;
                      &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                          &lt;HierarchicalDataTemplate ItemsSource="{Binding Childs}"&gt;
                              &lt;CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" /&gt;
  
                              &lt;!-- 3rd Child Level --&gt;
                              &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                                  &lt;DataTemplate&gt;
                                      &lt;CheckBox IsChecked="{Binding isChecked}" Content="{Binding naam}" /&gt;
                                  &lt;/DataTemplate&gt;
                              &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
  
                          &lt;/HierarchicalDataTemplate&gt;
                      &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
  
                  &lt;/HierarchicalDataTemplate&gt;
              &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
  
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/TreeView.ItemTemplate&gt;
      &lt;TreeView.ItemContainerStyle&gt;
          &lt;Style TargetType="{x:Type TreeViewItem}"&gt;
              &lt;Setter Property="IsExpanded"  Value="{Binding IsExpanded, Mode=TwoWay}"/&gt;
              &lt;Setter Property="Margin" Value="2"/&gt;
              &lt;!--&lt;Setter Property="IsSelected" Value="{Binding isSelected, Mode=TwoWay}"/&gt;
              &lt;EventSetter Event="Selected" Handler="TreeViewSelectedItemChanged" /&gt;--&gt;
          &lt;/Style&gt;
      &lt;/TreeView.ItemContainerStyle&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>