What is a good way to bubble up INotifyPropertyChanged events through ViewModel properties with MVVM?

一笑奈何 提交于 2019-12-03 10:15:10

If Address implements INotifyPropertyChanged and correctly raises PropertyChanged events on its City property then the binding should notice that the property it is bound to has changed.

Ben Gribaudo

Here's a SO thread containing a solution on how to bubble up these notifications: When nesting properties that implement INotifyPropertyChanged must the parent object propogate changes?

However, IIRC WPF has the intelligence to automatically monitor Address for INotifyPropertyChanged notifications when a control's binding is set to Address.City without PersonViewModel needing to re-broadcast the Address object's update notifications.

Does your Address object implement INotifyPropertyChanged? If not, I think that would fix the issue that you are seeing.

Edit: Sorry, just noticed that you mentioned in your post that you tried this already. Have you tried subscribing to the PropertyChanged event of the Address object in your PersonViewModel? OnChanged, you could perform a PropertyChanged on your Address object.

Check out PropertyChangedPropagator, it can handle dependencies on nested view models' properties including dynamically changeable nested view models: http://www.codeproject.com/Articles/775831/INotifyPropertyChanged-propagator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!