title: WPF Treeview Hierarchichal Datatemplate Groupstyle
body: <p>I have been struggling to add a GroupStyle to a Child of a Treeview inside a Hierarchical DataTemplate.</p>
  <p>Here is a drawing of my Treeview and how I would like the data to be represented.
  <a href="https://i.stack.imgur.com/iLBB1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iLBB1.png" alt="enter image description here" /></a></p>
  <p>I have everything except the gray border around the groups inside Layer3. I have tried a few things, but nothing worked. So I hope I can find some help here.</p>
  <p>All layers have their own Viewmodel.</p>
  <ul>
  <li>RootViewModel contains an ObservableCollection of Layer1 Objects</li>
  <li>A Layer1 object contains an ObservableCollection of Layer2 Objects</li>
  <li>A Layer2 object contains an ICollection of Layer3 Objects and also sets a Group Descriptor. The items are grouped by the first 5 characters of the Layer3 Objects name.</li>
  <li>A Layer3 object contains an ObservableCollection of Layer4 Objects</li>
  </ul>
  <p>This is the xaml of my Treeview</p>
  <pre><code>&lt;TreeView
      Name=&quot;Layer1&quot;
      ItemsSource=&quot;{Binding Path=Layer1s, IsAsync=True}&quot;&gt;
      &lt;TreeView.Resources&gt;
          &lt;Style BasedOn=&quot;{StaticResource TreeViewItemLayer1}&quot; TargetType=&quot;TreeViewItem&quot;&gt;
              ...
          &lt;/Style&gt;
      &lt;/TreeView.Resources&gt;
      &lt;TreeView.ItemContainerStyle&gt;
          &lt;Style BasedOn=&quot;{StaticResource TreeViewItemLayer1}&quot; TargetType=&quot;{x:Type TreeViewItem}&quot;&gt;
              ...
          &lt;/Style&gt;
      &lt;/TreeView.ItemContainerStyle&gt;
      &lt;TreeView.ItemTemplate&gt;
          &lt;HierarchicalDataTemplate DataType=&quot;{x:Type vm:Layer1ViewModel}&quot; ItemsSource=&quot;{Binding Path=Layer2s, IsAsync=True}&quot;&gt;
              &lt;Grid
                  ... some xaml elements
              &lt;/Grid&gt;
              &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;HierarchicalDataTemplate DataType=&quot;{x:Type vm:Layer2ViewModel}&quot; ItemsSource=&quot;{Binding Path=Layer3CollectionView, IsAsync=True}&quot;&gt;
                      &lt;Grid&gt;
                          some xaml elements
                      &lt;/Grid&gt;
                      &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                          &lt;HierarchicalDataTemplate DataType=&quot;{x:Type vm:Layer2ViewModel}&quot; ItemsSource=&quot;{Binding Path=Layer3CollectionView, IsAsync=True}&quot;&gt;
                              &lt;ItemsControl
                                  x:Name=&quot;Layer4Items&quot;
                                  Grid.Column=&quot;1&quot;
                                  ItemsSource=&quot;{Binding Layer4s}&quot;&gt;
                                  &lt;ItemsControl.ItemsPanel&gt;
                                      &lt;ItemsPanelTemplate&gt;
                                          &lt;WrapPanel
                                              x:Name=&quot;wrapContent&quot;
                                              Width=&quot;350&quot;
                                              Orientation=&quot;Horizontal&quot; /&gt;
                                      &lt;/ItemsPanelTemplate&gt;
                                  &lt;/ItemsControl.ItemsPanel&gt;
                                  &lt;ItemsControl.ItemTemplate&gt;
                                      &lt;DataTemplate DataType=&quot;{x:Type models:Layer4Model}&quot;&gt;
                                          ... some xaml elements
                                      &lt;/DataTemplate&gt;
                                  &lt;/ItemsControl.ItemTemplate&gt;
                              &lt;/ItemsControl&gt;
                          &lt;/HierarchicalDataTemplate&gt;
                      &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;/HierarchicalDataTemplate&gt;
              &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/TreeView.ItemTemplate&gt;
  &lt;/TreeView&gt;
  
  </code></pre>