title: Better performance from datagrid grouping
body: <p>I have a DataGrid which I am using with an ICollectionView to group items in a large collection, 20k+ rows in some instances. I have used this approach before with varying success with showing all rows or virtualizing to create a more responsive page. In this instance I would like to virtualize as much as possible to keep the UI responsive. I have used the tips in this answer with little success to my issues.
  <a href="https://stackoverflow.com/questions/13764579/improve-wpf-datagrid-performance/13765128#13765128">Helpful DataGrid Link</a></p>
  
  <p>My main issue is a couple second lag on the DataGrid when loading the data into the ICollectionView View/Source, which I would like to minimize with the proper virtualization. Here is some of my code:</p>
  
  <pre><code>&lt;DataGrid Margin="0,2,0,0" IsReadOnly="True" ItemsSource="{Binding DataView,IsAsync =True}" EnableRowVirtualization ="True" MaxWidth="2560" MaxHeight="1600"
                Grid.Row="2" SelectionMode="Extended" VirtualizingPanel.IsVirtualizingWhenGrouping="True" SelectionUnit="FullRow" SelectedItem="{Binding SelectedOutage}"&gt;
      &lt;DataGrid.GroupStyle&gt;
              &lt;GroupStyle&gt;
                  &lt;GroupStyle.ContainerStyle&gt;
                      &lt;Style TargetType="{x:Type GroupItem}"&gt;
                          &lt;Setter Property="Margin" Value="0,0,0,5"/&gt;
                          &lt;Setter Property="Template"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                      &lt;Expander IsExpanded="True" Foreground="{StaticResource Foreground}" Background="{StaticResource AlternatingBackground}"&gt;
                                          &lt;Expander.Header&gt;
                                              &lt;TextBlock Text="{Binding Name}" Margin="5,0,0,0" Width="300"/&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;/DataGrid.GroupStyle&gt;
          &lt;!--Follows are DataGrid.ContextMenu and DataGridTextColumns with fixed widths--&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>And c# items:</p>
  
  <pre><code>public ICollectionView DataView { get; set; }
  private readonly ObservableCollection&lt;EquipmentMonitorRow&gt; equipment = new ObservableCollection&lt;EquipmentMonitorRow&gt;();
  
  DataView = CollectionViewSource.GetDefaultView(equipment);
  DataView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
  
  equipment.Clear();
  //Lag is during this item adding.
  equipment.AddRange(data);
  </code></pre>
  
  <p>So hopefully I'm missing some virtualization or maybe I can add the items differently or something.
  Any help would be appreciated. Thanks.</p>