为什么ObservableCollection不会在项目更改时更新? [英] Why ObservableCollection is not updated on items change?
问题描述
我注意到WPF中的ObservableCollection
仅通过添加或删除列表中的项目而不是通过编辑它来反映GUI中的更改.
I noticed that ObservableCollection
in WPF reflects changes in GUI only by adding or removing an item in the list, but not by editing it.
这意味着我必须改写我的自定义类MyObservableCollection. 这种行为的原因是什么?
That means that I have to write my custom class MyObservableCollection instead. What is the reason for this behaviour?
谢谢
推荐答案
ObservableCollection无法知道是否对包含的对象进行了更改-如果要在这些对象更改时得到通知,则必须进行更改对象也可以观察到(例如,通过使这些对象实现INotifyPropertyChanged)
The ObservableCollection has no way of knowing if you make changes to the objects it contains - if you want to be notified when those objects change then you have to make those objects observable as well (for example by having those objects implement INotifyPropertyChanged)
这篇关于为什么ObservableCollection不会在项目更改时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!