title: WPF DataGrid GroupStyle
body: <p>I have the following <code>DataGrid</code> in WPF with two groups.<br>
  First group is a bool flag which represents if a person is active/inactive.<br>
  The second group (or sub-group) is the ID of each person.
  Each person can have multiple cities, therefore the grouping for the ID, because each person is shown multiple in the <code>DataGrid</code>.
  <img src="https://i.stack.imgur.com/RiYKD.jpg" alt="Table persons-cities"></p>
  
  <p>Here is the XAML:</p>
  
  <pre><code>&lt;DataGrid CanUserAddRows="False" AutoGenerateColumns="False" ItemsSource="{Binding DataSource}"&gt;     
      &lt;DataGrid.GroupStyle&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.Style&gt;
                                          &lt;Style TargetType="{x:Type Expander}"&gt;    
                                              &lt;Style.Triggers&gt;
                                                  &lt;DataTrigger Binding="{Binding Name}" Value="True"&gt;
                                                      &lt;Setter Property="Background" Value="{StaticResource ActiveBrush}"/&gt;
                                                  &lt;/DataTrigger&gt;
                                                  &lt;DataTrigger Binding="{Binding Name}" Value="False"&gt;
                                                      &lt;Setter Property="Background" Value="{StaticResource InactiveBrush}"/&gt;
                                                      &lt;Setter Property="FontStyle" Value="Italic"/&gt;
                                                      &lt;Setter Property="Foreground" Value="Gray"/&gt;
                                                  &lt;/DataTrigger&gt;
                                              &lt;/Style.Triggers&gt;
                                          &lt;/Style&gt;
                                      &lt;/Expander.Style&gt;
                                      &lt;Expander.Header&gt;
                                          &lt;StackPanel Orientation="Horizontal"&gt;
                                              &lt;TextBlock Text="{Binding Name, Converter={StaticResource BoolToTextConverter}}" Margin="5 2 5 2"/&gt;
                                              &lt;TextBlock Text=":" Margin="0 2 5 2"/&gt;
                                              &lt;TextBlock Text="{Binding ItemCount}" Margin="0 2 0 2"/&gt;
                                          &lt;/StackPanel&gt;
                                      &lt;/Expander.Header&gt;
                                          &lt;ItemsPresenter /&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;GroupStyle&gt;
              &lt;GroupStyle.HeaderTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" Background="LightSteelBlue"&gt;
                          &lt;TextBlock Text="{Binding Name}" Foreground="White" Margin="5 2 5 2"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/GroupStyle.HeaderTemplate&gt;
          &lt;/GroupStyle&gt;
      &lt;/DataGrid.GroupStyle&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel&gt;
                          &lt;DockPanel&gt;
                              &lt;Button BorderThickness="0" Content="Edit" Margin="3"
                                  Command="{Binding Commands.Edit}"
                                  CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/&gt;
                          &lt;/DockPanel&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
          &lt;DataGridTextColumn Header="ID" Binding="{Binding ID}" IsReadOnly="True"/&gt;
          &lt;DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True"/&gt;
          &lt;DataGridTextColumn Header="City" Binding="{Binding City}" IsReadOnly="True"/&gt;                    
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p><strong>It all works fine</strong>! 
  However, I don't like the blue row for each sub-group. 
  What I want to achieve is the grouping style in the following image:</p>
  
  <p><img src="https://i.stack.imgur.com/vYVF2.jpg" alt="Table persons-cities"></p>
  
  <p>For each sub-group I want the Edit button and the ID to appear only once per person.
  How would I do this? Is it possible in XAML only or should I remove the reduntant content in code-behind?</p>
  
  <p><strong>Edit</strong><br>
  Here some test data:</p>
  
  <pre><code>public class Person
  {
      public Person(bool active, int id, string name, string city)
      {
          Active = active;
          ID = id;
          Name = name;
          City = city;
      }
  
      public bool Active { get; set; }
      public int ID { get; set; }
      public string Name { get; set; }
      public string City { get; set; }
  }
  
  public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          DataContext = this;
  
          var data = new ObservableCollection&lt;Person&gt;
          {
              new Person(true, 233, "Max", "New York"),
              new Person(true, 233, "Max", "Los Angeles"),
              new Person(true, 314, "John", "Paris"),
              new Person(true, 578, "Mary", "Vienna"),
              new Person(true, 782, "Susan", "Rome"),
              new Person(true, 782, "Susan", "Prague"),
              new Person(true, 782, "Susan", "San Francisco"),
              new Person(false, 151, "Henry", "Chicago")
          };
  
          DataSource = new ListCollectionView(data);
      }
  
      private ListCollectionView _dataSource;
  
      public ListCollectionView DataSource
      {
          get { return _dataSource; }
          set
          {
              _dataSource = value;
              _dataSource.GroupDescriptions.Add(new PropertyGroupDescription("Active"));
              _dataSource.GroupDescriptions.Add(new PropertyGroupDescription("ID"));
          }
      } 
  </code></pre>