Created
November 26, 2015 20:36
-
-
Save dotMorten/7c2a4e790b9604e9efd9 to your computer and use it in GitHub Desktop.
Observable Collection supporting range adds efficiently without causing a lot of UI updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObservableCollection2<T> : ObservableCollection<T> | |
{ | |
public void AddRange(IEnumerable<T> items) | |
{ | |
InsertRange(Count, items); | |
} | |
public void InsertRange(int index, IEnumerable<T> items) | |
{ | |
int count = 0; | |
foreach(var item in items) | |
{ | |
base.Items.Insert(index + (count++), item); | |
} | |
OnPropertyChanged(new PropertyChangedEventArgs("Count")); | |
OnPropertyChanged(new PropertyChangedEventArgs("Items[]")); | |
OnCollectionChanged( | |
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, | |
changedItems: (System.Collections.IList)items.ToList(), | |
startingIndex: index)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment