C# 如何在NotifyCollectionChangedEventArgs中获取更改的项?

C# 如何在NotifyCollectionChangedEventArgs中获取更改的项?,c#,observablecollection,inotifypropertychanged,inotifycollectionchanged,C#,Observablecollection,Inotifypropertychanged,Inotifycollectionchanged,我创建了一个ObservableCollection,每当集合中对象(T:INPC)的属性发生更改时,它都会触发CollectionChangedEvent。我想知道T的哪个属性触发了CollectionChangedEvent,因此我尝试了以下操作: void item_PropertyChanged(object sender, PropertyChangedEventArgs e) { OnCollectionChanged(new NotifyCollec

我创建了一个ObservableCollection,每当集合中对象(T:INPC)的属性发生更改时,它都会触发CollectionChangedEvent。我想知道T的哪个属性触发了CollectionChangedEvent,因此我尝试了以下操作:

    void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, e));
    }
我将PropertyChangedEventArgs e传递给NotifyCollectionChangedEventArgs的构造函数

根据Intellisense,第二个构造函数接受两个参数:NotifyCollectionChangedAction和一个名为“changedObject”的对象,该对象被描述为“受更改影响的项”

所以我想我可以在CollectionChangedEventHandler中获取该对象并检查PropertyName,但是哦!惊喜NotifyCollectionChangedEventArgs不公开“ChangedObject”属性(我可以看到Action、NewItems、OldItems、NewStartingIndex、OldStartingIndex)


关于如何实现这一点有什么想法吗?顺便问一下,它用一个您以后无法访问的对象来构造NotifyCollectionChangedEventArgs有什么用?

当您使用
NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction,object)
构造函数时,
changedItem
将位于
NewItems
集合中(如果指定
NotifyCollectionChangedAction.Add
)或
OldItems
集合(如果指定
NotifyCollectionChangedAction.Remove

如果指定
NotifyCollectionChangedAction.Reset
,则
changedItem
参数必须为
null
,否则将得到
参数异常


如果您指定任何其他
NotifyCollectionChangedAction
值,那么当您使用
NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction,object)
构造函数时,
changedItem
也将在
NewItems
集合中(如果指定
NotifyCollectionChangedAction.Add
)或
OldItems
集合(如果指定
NotifyCollectionChangedAction.Remove

如果指定
NotifyCollectionChangedAction.Reset
,则
changedItem
参数必须为
null
,否则将得到
参数异常


如果指定任何其他
NotifyCollectionChangedAction
值,还将得到一个
ArgumentException

提示:NewItems和OldItems。提示:NewItems和OldItems。