How to handle add to list event?

后端 未结 10 2387
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 22:55

I have a list like this:

List list = new List

How to handle adding new position to this list?

When

10条回答
  •  悲&欢浪女
    2020-11-29 23:44

    I believe What you're looking for is already part of the API in the ObservableCollection(T) class. Example:

    ObservableCollection myList = new ObservableCollection();
    
    myList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
        delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)                    
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                MessageBox.Show("Added value");
            }
        }
    );
    
    myList.Add(1);
    

提交回复
热议问题