WPF DataBinding - 完全困惑
天哪! 我讨厌这个。 为什么这么复杂?
我想要做什么:
我有一个包含多个用户控件的表单,每个控件都有一个数据网格。 每个网格通过 .ItemSource 属性与 ObservableCollection 绑定,每次程序捕获事件时,它都会在隐含集合之一中进行更改。 但网格图片不会更新。
Gosh! I hate this. Why it is so complicated?
What I'm trying to do:
I have a form with several UserControls each with a DataGrid. Each grid bind with ObservableCollection through .ItemSource property, everytime when program catches an event, it makes changes in one of the implied collections. But a picture of a grid doesn't update.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果元素的属性发生更改,ObservableCollection 不会通知控件 - 除非元素通过 INotifyPropertyChanged 专门通知订阅者。
为什么会这样? 集合只是一个容器,虽然它知道元素的数量以及何时添加或删除元素,但它不知道元素的“内部内容”以及哪些属性应该引发通知。 即使您自己实现 INotifyPropertyChanged,您也需要决定更改哪些属性应引发事件。
ObservableCollection will not notify the control if a property of the element has changed - unless the element specifically notifies the subscribers through INotifyPropertyChanged.
Why it works this way? A collection is just a container, and while it knows about the number of the elements and when element was added or removed, it does not know "what is inside" of an element and what properties should raise notifications. Even when you implement the INotifyPropertyChanged yourself, you would need to decide changing of which properties should raise the event.