通过MVVM通过ViewModel属性使INotifyPropertyChanged事件冒泡的好方法是什么? [英] What is a good way to bubble up INotifyPropertyChanged events through ViewModel properties with MVVM?

查看:63
本文介绍了通过MVVM通过ViewModel属性使INotifyPropertyChanged事件冒泡的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出从ModelView中嵌套属性中冒出PropertyChanged事件的最佳方法.说我有一个ModelView PersonModelView,它具有一个属性PersonModelView.Address. Address依次具有属性City.当我绑定到City时,我会做类似{Binding Address.City}的事情.

I'm trying to figure out the best way to bubble up PropertyChanged events from nested Properties in my ModelView. Say I have my ModelView PersonModelView which has a Property PersonModelView.Address. Address in turn has a property City. When I bind to City in my view, I would do something like {Binding Address.City}.

我的问题是,即使Address实现了INotifyPropertyChanged,该绑定也不会得到更新,因为它正在处理PersonModelView上的PropertyChanged,而不是 Address.我认为我有两个选择:(1)将绑定的源(或更改DataContext)更改为Address属性,或(2)在Address对象上具有PersonModelView句柄PropertyChanged,以及用Address.City之类的东西来重新发射自己的PropertyChanged.

My problem is that even if Address implements INotifyPropertyChanged, the binding will not get updated because it is handling PropertyChanged on the PersonModelView, not Address. I think I have two options: (1) change the source of the binding (or change the DataContext) to the Address property or (2) have the PersonModelView handle PropertyChanged on the Address object and refire its own PropertyChanged with something like Address.City.

你们如何解决这个问题? (我目前正在使用MVVM light工具包,但对任何方法都感兴趣)

How are you guys solving this? (I'm using MVVM light toolkit at the mo, but am interested in any approaches)

推荐答案

如果Address实现INotifyPropertyChanged并在其City属性上正确引发了PropertyChanged事件,则绑定应注意其绑定到的属性已经改变了.

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.

这篇关于通过MVVM通过ViewModel属性使INotifyPropertyChanged事件冒泡的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆