title: Display treeviewitem as grid rows in wpf
body: <p>Basically in need to achieve something like this using treeview control in wpf: (random picture)</p>
  
  <p><a href="https://i.stack.imgur.com/3LovI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3LovI.png" alt=""></a><br>
  <sub>(source: <a href="http://blogs.msdn.com/blogfiles/delay/SimpleTreeGridUX.png" rel="noreferrer">msdn.com</a>)</sub>  </p>
  
  <p>Where nodes and child nodes have same headers.</p>
  
  <p>I googled a lot, but my knowledge in wpf not that good.</p>
  
  <p>Here is my parent node class:</p>
  
  <pre><code> public class Parent : PropertyChangedBase
      {
          public string ParentName { get; set; }
          public BindableCollection&lt;Child&gt; Children { get; set; }
      }
  </code></pre>
  
  <p>And child:</p>
  
  <pre><code>public class Child : PropertyChangedBase
  {
      public string ChildName { get; set; }
  }
  </code></pre>
  
  <p>My xaml tree view:</p>
  
  <pre><code>  &lt;TreeView Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Nodes}"&gt;
          &lt;TreeView.Resources&gt;
              &lt;HierarchicalDataTemplate DataType="{x:Type projectModels:Parent}" ItemsSource="{Binding Children}"&gt;
                  &lt;StackPanel&gt;
                      &lt;Grid&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="20"&gt;&lt;/ColumnDefinition&gt;
                              &lt;ColumnDefinition Width="Auto"&gt;&lt;/ColumnDefinition&gt;
                              &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;CheckBox Grid.Column="2"&gt;&lt;/CheckBox&gt;
                          &lt;TextBlock Grid.Column="1" Text="{Binding ParentName}"&gt;
                          &lt;/TextBlock&gt;
                      &lt;/Grid&gt;
                  &lt;/StackPanel&gt;
              &lt;/HierarchicalDataTemplate&gt;
              &lt;DataTemplate DataType="{x:Type projectModels:Child}"&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="{Binding ChildName}"&gt;&lt;/TextBlock&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/TreeView.Resources&gt;
      &lt;/TreeView&gt;
  </code></pre>
  
  <p>I tried using <code>Grid</code> but obviously it create different grids, so I can relay on column width.</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/1385372/how-to-make-gridview-a-child-element-of-a-treeview-in-wpf-application">How to make gridview a child element of a treeview in wpf application</a> , but they use <code>ListView</code>. It's not an option for me right now, as treeviewitem selection functionality is tightly coupled with my treeview and code behind.</p>
  
  <p>Any ideas how it can be done? Thanks.</p>