Provides ObservableRangeCollection and its WPF version, including AddRange, InsertRange, RemoveRange/RemoveAll, Replace/ReplaceRange methods for bulk operation to avoid frequent update notification events.
$ dotnet add package WpfObservableRangeCollectionProvides ObservableRangeCollection and its WPF version, including AddRange, InsertRange, RemoveRange/RemoveAll, Replace/ReplaceRange methods for bulk operation to avoid frequent update notification events.
PM> Install-Package WpfObservableRangeCollection
dotnet add package WpfObservableRangeCollection
ObservableRangeCollection: An ObservableCollection that supports bulk operations to avoid frequent update notification events.
Forked from weitzhandler/rangeobservablecollection-cs
WpfObservableRangeCollection: WPF version of ObservableRangeCollection with CollectionView support.
Forked from weitzhandler/wpfobservablerangecollection-cs
var collection = new WpfObservableRangeCollection<int>();
collection.AddRange(Enumerable.Range(0,10));
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
collection.RemoveRange(index: 5, count: 3);
{ 0, 1, 2, 3, 4,
5, 6, 78, 9 }
// You can also receive the return value to get the number of items that were successfully removed.
// removed here is 2.
int removed = collection.RemoveRange(new[] { 1, 3, 5 });
{ 0,
12,34, 8, 9 }
collection.InsertRange(index: 2, collection: Enumerable.Range(10, 7));
{ 0, 2, 10, 11, 12, 13, 14, 15, 16, 4, 8, 9 }
// This method is roughly equivalent to RemoveRange, then InsertRange.
// When index and count are equal to 0, it is equivalent to InsertRange(0, collection).
// changed here is 0.
int changed = collection.ReplaceRange(index: 6, count: 3, new[] { -1, -2, -3 });
{ 0, 2, 10, 11, 12, 13, -1, -2, -3, 4, 8, 9 }
// Clears the current collection and replaces it with the specified item.
collection.Replace(42);
{ 42 }
AllowDuplicates = false, and you can specify the Comparer = xxx.I've searched the web for some ObservableCollections that have *Range methods, but they all raise various exceptions(and some strange problems) in certain specific situations:
In the end, I chose weitzhandler/RangeObservableCollection and weitzhandler/WpfObservableRangeCollection and made slight changes to the code, and finally, I didn't encounter any problems, for now.
If the
NotSupportedExceptionstill occurred, try usingBindingOperations.EnableCollectionSynchronization(IEnumerable, Object).