可观察集合数据网格
我将 ObservableCollection 绑定到 dataGrid itemssource。
仅当我们添加、删除、移除时,可观察集合的 collectionChangedEvent 才会被调用。但当我们更新记录时不会触发。
如何也触发更新事件?
I bound the ObservableCollection to the dataGrid itemssource.
the collectionChangedEvent of the observable Collection is getting called only when we add, delete, remove. But not firing when we update the record.
how to fire the event for Update too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在某个项目发生更改时收到通知(即您想订阅此事件),那么
ObservableCollection
就不那么幸运了,因为此集合仅触发CollectionChangedEvent< /代码>。
事实上,如果您实现 INotifyPropertyChanged,您将看到视图中项目的更改(WPF 自动执行此操作),但如果您需要在项目更改时执行手动操作,则可以使用
BindingList
。正是针对这种情况,我推出了一个自定义
BindableCollection
,它实现ObservableCollection
并添加OnItemChangedEvent
。如果需要的话我可以提供一些示例代码...If you want to be notified when an item is changed (ie you want to subscribe to this event), you are out of luck with
ObservableCollection<T>
because this collection only fires theCollectionChangedEvent
.Indeed, if you implement
INotifyPropertyChanged
, you will see changes to the items in the view (WPF does this automatically), but if you need to execute manual actions when an item changes, you can useBindingList<T>
.For exactly this scenario I rolled out a custom
BindableCollection<T>
, which implementsObservableCollection<T>
and adds theOnItemChangedEvent
. I can provide some sample code if necessary...集合不知道记录何时被修改。要在发生这种情况时收到通知,记录需要实现
INotifyPropertyChanged
The collection doesn't know when the record is modified. To get a notification when this happens, the record needs to implement
INotifyPropertyChanged