通过MVVM通过ViewModel属性使INotifyPropertyChanged事件冒泡的好方法是什么? [英] What is a good way to bubble up INotifyPropertyChanged events through ViewModel properties with MVVM?
问题描述
我试图找出从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屋!