public ObservableCollection<IndividualEntityCsidClidDetail> IncludedMembers { get; set; }

假设我有一个IncludedMembers的引用,我希望添加/删除/编辑收集项时发生一个事件。

最佳答案

处理CollectionChanged事件

//注册事件,以便每次集合更改时都会调用CollectionChangedMethod方法

    yourCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler
(CollectionChangedMethod);

创建这样的方法
private void CollectionChangedMethod(object sender, NotifyCollectionChangedEventArgs e)
{
       //different kind of changes that may have occurred in collection
       if(e.Action == NotifyCollectionChangedAction.Add)
        {
            //your code
        }
        if (e.Action == NotifyCollectionChangedAction.Replace)
        {
            //your code
        }
        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            //your code
        }
        if (e.Action == NotifyCollectionChangedAction.Move)
        {
            //your code
        }
}

关于c# - 如何获取ObservableCollection中的更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6007765/

10-13 03:11