以下の内容はhttps://nomoredeathmarch.hatenablog.com/entry/2019/03/19/220044より取得しました。


C# ListをラップしたObservableCollectionのイベント

ObservableCollectionはコンストラクタにListを渡して生成することが出来る。が、生成した後にListクラスを通じてコレクションを編集してもコレクション変更イベントは発生しない。

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>();
            var observable = new ObservableCollection<int>(list);
            observable.CollectionChanged += Observable_CollectionChanged;

            list.Add(1);
            list.Add(2);
            list.Add(3);
            Console.ReadKey();
        }

        private static void Observable_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Console.WriteLine("Observable_CollectionChanged Called!!");
        }
    }
}
|cs|<



以上の内容はhttps://nomoredeathmarch.hatenablog.com/entry/2019/03/19/220044より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14