title: How to add additional property counts to Grouped WPF Datagrid Items?
body: <p>I have a WPF app that communicates with a 3rd party app to gather updates from.
  These updates are then put into a Updates Collection and displayed into a Datagrid.</p>
  
  <p>The update class:</p>
  
  <pre><code>public class UpdateEntry
  {
      public string UserID { get; set; }
      public string UserName { get; set; }
      public DateTime TimeOfUpdate { get; set; }
      public string Reference { get; set; }
  }
  </code></pre>
  
  <p>As per in this tutorial: <a href="http://wpftutorial.net/DataGrid.html" rel="nofollow noreferrer">http://wpftutorial.net/DataGrid.html</a></p>
  
  <p>I have grouped the results by the <strong>UserName</strong> field: </p>
  
  <pre><code>Updates = CollectionViewSource.GetDefaultView(UserUpdates);
  GroupedUpdates = new ListCollectionView(UserUpdates);
  GroupedUpdates.GroupDescriptions.Add(new PropertyGroupDescription("UserName"));
  </code></pre>
  
  <p>and am able to show the number of updates entries as per the <strong>ItemCount</strong> property as shown here:</p>
  
  <pre><code>&lt;TextBlock Text="{Binding Path=Name}" /&gt;
  &lt;TextBlock Text="{Binding Path=ItemCount}" Margin="8,0,4,0"/&gt;
  &lt;TextBlock Text="Updates"/&gt;
  </code></pre>
  
  <p>What I would like to be able to do is also display a <strong>Reference</strong> <strong><em>Count</em></strong>, next to this <strong>UpdateEntry</strong> <strong><em>Count</em></strong>, ie. number of References per person (<strong>UserName</strong>).</p>
  
  <p>FYI: There are multiple updates per Reference and per person.</p>
  
  <p>I do have a User Summary Class which assists with populating the name and storing the number of Handled References per User, but I'm not sure how I would use this in context with the DataGrid:</p>
  
  <pre><code>public UserSummary(){ HandledReferences = new List&lt;ReferenceInstance&gt;();}
  
      public string UserID {get;set;}
  
      public string UserName {get;set;}
  
      public List&lt;Models.ReferenceInstance&gt; HandledReferences {get;set;}
  
      public int NumberOfReferences { get { return HandledReferences.Count; }}
  </code></pre>
  
  <p><em>I've excluded some fields for simplicity and conciseness</em></p>
  
  <p>Here is an example of what I'd like to achieve:</p>
  
  <p><strong>Bobby Boo - Updates: 4  References: 2</strong> </p>
  
  <ul>
  <li><p>UserID: BB03, UserName: Bobby Boo, Time: 10:24, Reference: A11</p></li>
  <li><p>UserID: BB03, UserName: Bobby Boo, Time: 10:51, Reference: A11</p></li>
  <li><p>UserID: BB03, UserName: Bobby Boo, Time: 11:54, Reference: C99</p></li>
  <li><p>UserID: BB03, UserName: Bobby Boo, Time: 12:09, Reference: C99</p></li>
  </ul>
  
  <p><strong>Mike Larry - Updates: 2  References: 1</strong> </p>
  
  <ul>
  <li><p>UserID: NW01, UserName: Mike Larry, Time: 15:22, Reference: B22</p></li>
  <li><p>UserID: NW01, UserName: Mike Larry, Time: 17:12, Reference: B22</p></li>
  </ul>
  
  <p><strong>Additional Info:</strong></p>
  
  <p>Here is a bigger look at the Control Template on the Datagrid Grouping:</p>
  
  <pre><code>&lt;DataGrid DockPanel.Dock="Left" ItemsSource="{Binding GroupedUpdates}" IsReadOnly="True" Background="LightSlateGray"&gt;
          &lt;DataGrid.GroupStyle&gt;
              &lt;GroupStyle&gt;
                  &lt;GroupStyle.HeaderTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel&gt;
                              &lt;TextBlock Text="{Binding Path=Name}" Padding="3"/&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/GroupStyle.HeaderTemplate&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&gt;
                                          &lt;Expander.Header&gt;
                                              &lt;StackPanel Orientation="Horizontal"&gt;
                                                  &lt;StackPanel.Resources&gt;
                                                      &lt;Style TargetType="TextBlock"&gt;
                                                          &lt;Setter Property="FontSize" Value="13" /&gt;
                                                          &lt;Setter Property="FontWeight" Value="Bold" /&gt;
                                                          &lt;Setter Property="Foreground" Value="White"/&gt;
                                                      &lt;/Style&gt;
                                                  &lt;/StackPanel.Resources&gt;
                                                  &lt;TextBlock Text="{Binding Path=Name}" /&gt;
                                                  &lt;TextBlock Text="{Binding Path=ItemCount}" Margin="8,0,4,0"/&gt;
                                                  &lt;TextBlock Text="Updates"/&gt;
                                              &lt;/StackPanel&gt;
                                          &lt;/Expander.Header&gt;
                                          &lt;ItemsPresenter /&gt;
                                      &lt;/Expander&gt;
                                  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>and a screenshot of the double grouping / figures I'm trying to capture:</p>
  
  <p><img src="https://i.stack.imgur.com/ky1RM.jpg" alt="UserName and Reference Groups Example"></p>