title: Group WPF DataGrid expander
body: <p>I would like to regroup all <code>ClassMate</code> of same <code>GroupName</code> with an expander...</p>
  
  <pre><code>&lt;DataGrid x:Name="gridMates" ItemsSource="{Binding Groups}"&gt;
  </code></pre>
  
  <p>With <code>BindingGroup</code>s.<br>
  These groups are composed by:</p>
  
  <pre><code>public class Group
  { 
      public List&lt;ClassMate&gt; CLGroup { get; set; }
      public string GroupName { get; set; }
  }
  </code></pre>
  
  <p>My <code>ClassMate</code> class is:</p>
  
  <pre><code>public class ClassMate: INotifyPropertyChanged
  {
      public string Name { get; set; }
      public string DisplayName { get; set; }}
  </code></pre>
  
  <p>My XAML is:</p>
  
  <pre><code>&lt;DataGrid x:Name="gridMates"  ItemsSource="{Binding Groups }"  &gt;
          &lt;DataGrid.GroupStyle&gt;
              &lt;!-- Style for groups at top level. --&gt;
              &lt;GroupStyle&gt;
                  &lt;GroupStyle.ContainerStyle&gt;
                      &lt;Style TargetType="{x:Type GroupItem}"&gt;
                          &lt;Setter Property="Template"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                      &lt;Expander IsExpanded="True" &gt;
                                          &lt;Expander.Header&gt;
                                              &lt;DockPanel&gt;
  
                                              &lt;TextBlock Text="{Binding Path=GroupName}" /&gt;
                                          &lt;/DockPanel&gt;
                                          &lt;/Expander.Header&gt;
                                          &lt;Expander.Content&gt;
                                              &lt;ItemsControl ItemsSource="{Binding Path=CLGroup}"&gt;
                                                  &lt;ItemsControl.ItemTemplate&gt;
                                                      &lt;DataTemplate&gt;
                                                          &lt;StackPanel&gt;
                                                              &lt;TextBlock   Text="{Binding Path=DisplayName}"/&gt;
  
                                                          &lt;/StackPanel&gt;
  
                                                      &lt;/DataTemplate&gt;
                                                  &lt;/ItemsControl.ItemTemplate&gt;
                                              &lt;/ItemsControl&gt;
                                          &lt;/Expander.Content&gt;
                                      &lt;/Expander&gt;
                                  &lt;/ControlTemplate&gt;
                              &lt;/Setter.Value&gt;
                          &lt;/Setter&gt;
                      &lt;/Style&gt;
                  &lt;/GroupStyle.ContainerStyle&gt;
              &lt;/GroupStyle&gt;
  
          &lt;/DataGrid.GroupStyle&gt;
  </code></pre>
  
  <p>I tried in this way, but doesn't works.
  How to regroup them? Could you help me?
  Thanks</p>