WpfObservableRangeCollection 2.2.1

dotnet add package WpfObservableRangeCollection --version 2.2.1                
NuGet\Install-Package WpfObservableRangeCollection -Version 2.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WpfObservableRangeCollection" Version="2.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WpfObservableRangeCollection --version 2.2.1                
#r "nuget: WpfObservableRangeCollection, 2.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WpfObservableRangeCollection as a Cake Addin
#addin nuget:?package=WpfObservableRangeCollection&version=2.2.1

// Install WpfObservableRangeCollection as a Cake Tool
#tool nuget:?package=WpfObservableRangeCollection&version=2.2.1                

WpfObservableRangeCollection

NuGet Target framework Target framework GitHub issues GitHub stars GitHub license CodeFactor

Provides ObservableRangeCollection and its WPF version, including AddRange, InsertRange, RemoveRange/RemoveAll, Replace/ReplaceRange methods for bulk operation to avoid frequent update notification events.

NuGet Package Manager

PM> Install-Package WpfObservableRangeCollection

.NET CLI

dotnet add package WpfObservableRangeCollection

Classes

Usage

var collection = new WpfObservableRangeCollection<int>();
collection.AddRange(Enumerable.Range(0,10));

{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

</br>

collection.RemoveRange(index: 5, count: 3);

{ 0, 1, 2, 3, 4, 5, 6, 7 8, 9 }

</br>

// 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, 1 2, 3 4, 8, 9 }

</br>

collection.InsertRange(index: 2, collection: Enumerable.Range(10, 7));

{ 0, 2, 10, 11, 12, 13, 14, 15, 16, 4, 8, 9 }

</br>

// 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 }

</br>

// Clears the current collection and replaces it with the specified item.
collection.Replace(42);

{ 42 }

</br>

  • If duplicate items are not allowed in the collection, set AllowDuplicates = false, and you can specify the Comparer = xxx.
  • Most of the extended methods have return values to indicate changes in the number of collections.

Why WpfObservableRangeCollection?

See ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging? - StackOverflow

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:

  • System.NotSupportedException: Range actions are not supported.
  • System.InvalidOperationException: The "x" index in the collection change event is not valid for collections of size "y".
  • More? I'm not sure. I forgot.

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 NotSupportedException still occurred, try using BindingOperations.EnableCollectionSynchronization(IEnumerable, Object).

Seealso

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.1 519 11/16/2023
2.2.0 370 7/28/2023
2.1.0 203 7/23/2023
2.0.1 180 7/23/2023
2.0.0 165 7/23/2023
1.0.0 169 7/22/2023