MintPlayer.ObservableCollection 1.2.0

Extended version of System.Collections.ObjectModel.ObservableCollection. This class allows you to:
   1) Use AddRange, invoking the CollectionChanged event only once
   2) Use RemoveRange, invoking the CollectionChanged event only once
   3) Monitor properties of the items in the collection
   4) Add/Remove/Replace items from another thread
   5) Support for WPF

There is a newer version of this package available.
See the version list below for details.
Install-Package MintPlayer.ObservableCollection -Version 1.2.0
dotnet add package MintPlayer.ObservableCollection --version 1.2.0
<PackageReference Include="MintPlayer.ObservableCollection" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MintPlayer.ObservableCollection --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MintPlayer.ObservableCollection, 1.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MintPlayer.ObservableCollection as a Cake Addin
#addin nuget:?package=MintPlayer.ObservableCollection&version=1.2.0

// Install MintPlayer.ObservableCollection as a Cake Tool
#tool nuget:?package=MintPlayer.ObservableCollection&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MintPlayer.ObservableCollection

Extended version of System.Collections.ObjectModel.ObservableCollection. This class allows you to:

  1. Use AddRange, invoking the CollectionChanged event only once
  2. Monitor properties of the items in the collection

NuGet package

https://www.nuget.org/packages/MintPlayer.ObservableCollection/

Installation

NuGet package manager

Open the NuGet package manager and install the MintPlayer.ObservableCollection package in the project

Package manager console

Install-Package MintPlayer.ObservableCollection

Usage

Example 1

var collection = new ObservableCollection<string>();
collection.CollectionChanged += (sender, e) =>
{
    Console.WriteLine($"Collection changed:");
    if (!e.NewItems.IsNullOrEmpty())
    {
        var newItemsArray = new string[e.NewItems.Count];
        e.NewItems.CopyTo(newItemsArray, 0);
        Console.WriteLine($"- items added: {string.Join(", ", newItemsArray)}");
    }
    if (!e.OldItems.IsNullOrEmpty())
    {
        var oldItemsArray = new string[e.OldItems.Count];
        e.OldItems.CopyTo(oldItemsArray, 0);
        Console.WriteLine($"- items removed: {string.Join(", ", oldItemsArray)}");
    }
};

collection.Add("Michael");
//collection.Enabled = false;
collection.Add("Junior");
//collection.Enabled = true;
collection.Add("Jackson");

Example 2

public class Person : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    private string firstname;
    public string FirstName
    {
        get { return firstname; }
        set
        {
            firstname = value;
            OnPropertyChanged();
        }
    }

    private string lastname;
    public string LastName
    {
        get { return lastname; }
        set
        {
            lastname = value;
            OnPropertyChanged();
        }
    }

    public string FullName => $"{firstname} {lastname}";
}

Program.cs

var collection = new ObservableCollection<Person>();
collection.CollectionChanged += (sender, e) =>
{
    Console.WriteLine($"Collection changed:");
    if (!e.NewItems.IsNullOrEmpty())
    {
        var newItemsArray = new Person[e.NewItems.Count];
        e.NewItems.CopyTo(newItemsArray, 0);
        Console.WriteLine($"- items added: {string.Join(", ", newItemsArray.Select(p => p.FullName))}");
    }
    if (!e.OldItems.IsNullOrEmpty())
    {
        var oldItemsArray = new Person[e.OldItems.Count];
        e.OldItems.CopyTo(oldItemsArray, 0);
        Console.WriteLine($"- items removed: {string.Join(", ", oldItemsArray.Select(p => p.FullName))}");
    }
};
collection.ItemPropertyChanged += (sender, e) =>
{
    Console.WriteLine($"Item property changed: {e.PropertyName}");
};

var person1 = new Person { FirstName = "John", LastName = "Doe" };
var person2 = new Person { FirstName = "Jimmy", LastName = "Fallon" };
var person3 = new Person { FirstName = "Michael", LastName = "Douglas" };

// Add 3 items at once
collection.AddRange(new[] {
    person1,
    person2,
    person3
});

// Change an item property
collection[1].LastName = "Knibble";

// Remove 2 items at once
collection.RemoveRange(new[] { person1, person3 });

MintPlayer.ObservableCollection

Extended version of System.Collections.ObjectModel.ObservableCollection. This class allows you to:

  1. Use AddRange, invoking the CollectionChanged event only once
  2. Monitor properties of the items in the collection

NuGet package

https://www.nuget.org/packages/MintPlayer.ObservableCollection/

Installation

NuGet package manager

Open the NuGet package manager and install the MintPlayer.ObservableCollection package in the project

Package manager console

Install-Package MintPlayer.ObservableCollection

Usage

Example 1

var collection = new ObservableCollection<string>();
collection.CollectionChanged += (sender, e) =>
{
    Console.WriteLine($"Collection changed:");
    if (!e.NewItems.IsNullOrEmpty())
    {
        var newItemsArray = new string[e.NewItems.Count];
        e.NewItems.CopyTo(newItemsArray, 0);
        Console.WriteLine($"- items added: {string.Join(", ", newItemsArray)}");
    }
    if (!e.OldItems.IsNullOrEmpty())
    {
        var oldItemsArray = new string[e.OldItems.Count];
        e.OldItems.CopyTo(oldItemsArray, 0);
        Console.WriteLine($"- items removed: {string.Join(", ", oldItemsArray)}");
    }
};

collection.Add("Michael");
//collection.Enabled = false;
collection.Add("Junior");
//collection.Enabled = true;
collection.Add("Jackson");

Example 2

public class Person : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    private string firstname;
    public string FirstName
    {
        get { return firstname; }
        set
        {
            firstname = value;
            OnPropertyChanged();
        }
    }

    private string lastname;
    public string LastName
    {
        get { return lastname; }
        set
        {
            lastname = value;
            OnPropertyChanged();
        }
    }

    public string FullName => $"{firstname} {lastname}";
}

Program.cs

var collection = new ObservableCollection<Person>();
collection.CollectionChanged += (sender, e) =>
{
    Console.WriteLine($"Collection changed:");
    if (!e.NewItems.IsNullOrEmpty())
    {
        var newItemsArray = new Person[e.NewItems.Count];
        e.NewItems.CopyTo(newItemsArray, 0);
        Console.WriteLine($"- items added: {string.Join(", ", newItemsArray.Select(p => p.FullName))}");
    }
    if (!e.OldItems.IsNullOrEmpty())
    {
        var oldItemsArray = new Person[e.OldItems.Count];
        e.OldItems.CopyTo(oldItemsArray, 0);
        Console.WriteLine($"- items removed: {string.Join(", ", oldItemsArray.Select(p => p.FullName))}");
    }
};
collection.ItemPropertyChanged += (sender, e) =>
{
    Console.WriteLine($"Item property changed: {e.PropertyName}");
};

var person1 = new Person { FirstName = "John", LastName = "Doe" };
var person2 = new Person { FirstName = "Jimmy", LastName = "Fallon" };
var person3 = new Person { FirstName = "Michael", LastName = "Douglas" };

// Add 3 items at once
collection.AddRange(new[] {
    person1,
    person2,
    person3
});

// Change an item property
collection[1].LastName = "Knibble";

// Remove 2 items at once
collection.RemoveRange(new[] { person1, person3 });

  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MintPlayer.ObservableCollection:

Package Downloads
KarnaughMap
This package contains a .NET Core Windows Forms control that renders a Karnaugh-map which is fully interactive.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.5.0 91 7/22/2021
1.4.0 74 6/28/2021
1.3.0 145 6/25/2021
1.2.2 267 11/7/2020
1.2.1 179 9/17/2020
1.2.0 223 7/7/2020
1.2.0-preview3 143 7/7/2020
1.2.0-preview2 148 7/7/2020
1.2.0-preview1 146 7/7/2020
1.1.1 167 7/7/2020
1.1.0 155 7/7/2020
1.0.7 136 7/7/2020
1.0.6 229 6/28/2020
1.0.5 235 6/27/2020
1.0.4 274 6/27/2020
1.0.3 175 6/8/2020
1.0.2 154 6/5/2020
1.0.1 160 6/5/2020
1.0.0 271 10/18/2019
Show less