C# Observable Collections


#1

I would like to request official support for ObservableCollections to be used.

[Edit: Correct namespaces: using System.Collections.ObjectModel; using System.Collections.Specialized;]

If another method exists to trigger an event after Add / Delete of a list item, I would also be open to that alternative.

The goal would also be to avoid writing a custom wrapper for List() .Add / .Remove, it starts to cause issues with built in list functionality.

An example of the type of functionality I would like to see is outlined here: https://stackoverflow.com/questions/4279185/what-is-the-use-of-observablecollection-in-net

While a different use case, functionally it is the same. (For those who don’t want to click through, representative code below)

class Handler
{

    private ObservableCollection<string> collection;

    public Handler()
    {
        collection = new ObservableCollection<string>();
        collection.CollectionChanged += HandleChange;
    }

    private void HandleChange(object sender, NotifyCollectionChangedEventArgs e)
    {
        foreach (var x in e.NewItems)
        {
            // do something
        }

        foreach (var y in e.OldItems)
        {
            //do something
        }
        if (e.Action == NotifyCollectionChangedAction.Move)
        {
            //do something
        }
    }
}

When attempting as of build 344 (Windows) FX-Server hard crashes.