Skip to content

ObservableCollectionWithAddRange adds the AddRange and ClearAndAddRange methods to the ObservableCollection.

License

Notifications You must be signed in to change notification settings

denxorz/ObservableCollectionWithAddRange

Repository files navigation

ObservableCollectionWithAddRange

.Build status Coverage Status NuGet License

What does it do?

ObservableCollectionWithAddRange adds the AddRange and ClearAndAddRange methods to the ObservableCollection.

This can be used to speed up operations with WPF collection bindings that handle a lot of changes.

This package is based on the following articles:

Examples

What it looks like with the default System.Collections.ObjectModel.ObservableCollection:

var collection = new ObservableCollection<int> { 1, 2 };
collection.CollectionChanged += (s, e) => Console.WriteLine($"CollectionChanged: {e.Action}");

// Array with new items
var newItems = new[] { 3, 4, 5 };

// Replace all items by new items
collection.Clear();
foreach (var item in newItems)
{
    collection.Add(item);
}

// Output:
//   CollectionChanged: Reset
//   CollectionChanged: Add
//   CollectionChanged: Add
//   CollectionChanged: Add

What it looks like with ObservableCollectionWithAddRange:

// Denxorz.ObservableCollectionWithAddRange
var collection = new ObservableCollectionWithAddRange<int> { 1, 2 };
collection.CollectionChanged += (s, e) => Console.WriteLine($"CollectionChanged: {e.Action}");

// Array with new items
var newItems = new[] { 3, 4, 5 };

// Replace all items by new items
collection.ClearAndAddRange(newItems);

// Output:
//   CollectionChanged: Reset

Tools and Products Used

Versions & Release Notes

version 2.1.2: Added .NET 8.0

version 2.1.1: Added .NET 5.0

version 2.1: Added .NET Framework 4.5.2 again

version 2.0: Converted to .NET Standard 2.0

version 1.0: First version (.NET Framework 4.5.2)

About

ObservableCollectionWithAddRange adds the AddRange and ClearAndAddRange methods to the ObservableCollection.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages