title: Treeview Header in WPF xaml
body: <p>I am having a treeview in my wpf application which dynamically binds data from my viewmodel.</p>
  
  <pre><code>&lt;TreeView Grid.Column="0"
            Grid.Row="0"
            ItemsSource="{Binding Main}"
            HorizontalAlignment="Stretch"
            Name="treeView1"
            VerticalAlignment="Stretch"
            Height="auto"
            Width="auto"
            SelectedItemChanged="treeView1_SelectedItemChanged"
            HorizontalContentAlignment="Stretch"
            VerticalContentAlignment="Top"
            Margin="0,0,5,5"&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="IsSelected"
                Value="{Binding IsSelected, Mode=TwoWay}" /&gt;
        &lt;Setter Property="FontWeight"
                Value="Normal" /&gt;
        &lt;Style.Triggers&gt;
          &lt;Trigger Property="IsSelected"
                   Value="True"&gt;
            &lt;Setter Property="FontWeight"
                    Value="Bold" /&gt;
          &lt;/Trigger&gt;
        &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
    &lt;/TreeView.ItemContainerStyle&gt;
    &lt;TreeView.Resources&gt;
      &lt;HierarchicalDataTemplate DataType="{x:Type local:MViewModel}"
                                ItemsSource="{Binding Children}"&gt;
        &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBlock Text="{Binding Mname}" /&gt;
        &lt;/StackPanel&gt;
      &lt;/HierarchicalDataTemplate&gt;
      &lt;HierarchicalDataTemplate DataType="{x:Type local:FViewModel}"
                                ItemsSource="{Binding Children}"&gt;
        &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBlock Text="{Binding FName}" /&gt;
        &lt;/StackPanel&gt;
      &lt;/HierarchicalDataTemplate&gt;
      &lt;HierarchicalDataTemplate DataType="{x:Type local:CViewModel}"
                                ItemsSource="{Binding Children}"&gt;
        &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBlock Text="{Binding Com}" /&gt;
        &lt;/StackPanel&gt;
      &lt;/HierarchicalDataTemplate&gt;
      &lt;DataTemplate DataType="{x:Type local:LViewModel}"&gt;
        &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBlock Text="{Binding Lo}" /&gt;
        &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
    &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>I need to add the header to the whole treeview say "Family" whose childs are the above treeview elements.
  How can i add header to the whole treeview.so that when i click that header it should display all Mname and so on.
  Please help me with this issue.</p>
  
  <p>Edit:</p>
  
  <p>i have used</p>
  
  <pre><code>  &lt;HierarchicalDataTemplate  DataType="{x:Type TextBlock}" ItemsSource="{Binding Children}"&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;TextBlock Text="Family" /&gt;
                          &lt;/StackPanel&gt;
    &lt;/HierarchicalDataTemplate&gt;
  </code></pre>
  
  <p>in my TreeviewResource. But still i can't assign the parent for the tree.</p>
  
  <p>Edit 2:</p>
  
  <pre><code>&lt;TreeView&gt;
     &lt;TreeViewItem ItemsSource="{Binding Main}" Header="Family"&gt;
        &lt;TreeViewItemContainerStyle&gt;
        //..
        &lt;/TreeViewItemContainerStyle&gt;
        &lt;TreeView.Resources&gt;
        //..
        &lt;/TreeView.Resources&gt;
     &lt;/TreeViewItem&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>Its showing error.</p>
  
  <p>But when i do like below,</p>
  
  <pre><code>&lt;TreeView&gt;
         &lt;TreeViewItemContainerStyle&gt;
        //..
        &lt;/TreeViewItemContainerStyle&gt;
        &lt;TreeView.Resources&gt;
        //..
        &lt;/TreeView.Resources&gt;
     &lt;TreeViewItem ItemsSource="{Binding Main}" Header="Family"/&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>The root item has been set. But Only the first set of child are displayed. Childs of child elements are not displaying.</p>