title: WPF DataGrid repaints all the time
body: <p>I'm adding multiple elements to an ObservableCollection binded to a DataGrid from another process. I've tried to add elements one by one, and using a custom ObservableCollection to add a range like this:</p>
  
  <pre><code>public void AddRange(IEnumerable&lt;T&gt; range)
  {
      foreach (var item in range)
          this.Items.Add(item);
  
      this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
      this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
      this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
  }
  </code></pre>
  
  <p>Using the AddRange method the UI freezes a lot (it's completely unusable while adding items), probably because of the reset event. Using the WPF Performance Profiling Tools I see that the DataGrid repaints completely all the time, even with virtualization. I'm using the following code in the DataGrid to activate the virtualization:</p>
  
  <pre><code>VirtualizingStackPanel.IsVirtualizing="True"
  VirtualizingStackPanel.IsVirtualizingWhenGrouping="True"
  VirtualizingStackPanel.ScrollUnit="Pixel"
  VirtualizingStackPanel.VirtualizationMode="Recycling"
  </code></pre>
  
  <p>Trying to use a normal ObservableCollection and adding one by one is better but still repaints with each item even if its not visible and is still slow, the frame rate halves.</p>
  
  <p>Is there something I'm missing to make the performance better? It's possible for the DataGrid to not repaint everything when adding item/s (that its/are supossed to be invisible and not "painted" because of virtualization)?</p>