MVVM in WPF - How to alert ViewModel of changes in Model… or should I?

前端 未结 11 700
离开以前
离开以前 2020-11-27 09:51

I am going through some MVVM articles, primarily this and this.

My specific question is: How do I communicate Model changes from the Model to the ViewModel?<

11条回答
  •  情话喂你
    2020-11-27 10:24

    I have been advocating the directional Model -> View Model -> View flow of changes for a long time now, as you can see in the Flow of Changes section of my MVVM article from 2008. This requires implementing INotifyPropertyChanged on the model. As far as I can tell, it's since become common practice.

    Because you mentioned Josh Smith, take a look at his PropertyChanged class. It's a helper class for subscribing to the model's INotifyPropertyChanged.PropertyChanged event.

    You can actually take this approach much further, as I have recenty by creating my PropertiesUpdater class. Properties on the view-model are computed as complex expressions that include one or more properties on the model.

提交回复
热议问题