Let’s say I’ve got a View. It’s DataContext is bound to a ViewModel and the ViewModel exposes a Model property.
- Is it
MVVMlike to bind fields in theViewto properties in theModel(e.g.Binding Path=Model.FirstName)? - Should the
ModelimplementINotifyPropertyChanged?
My team are using Prism and MVVM in WPF. A lot of the Prism examples bind indirectly to the Model. I personally have my doubts that this is the correct approach. I think stuff in the model should expose behaviour (not just at the property level) and should communicate important events by, er, events – that clients can subscribe to or not.
I think that by having domain/model objects implement INotifyPropertyChanged somehow says to the world that it’s UI/UX aware and kind of introduces some redundancy in the ViewModels.
What do you think? What works for you? A clear distinction between View/ViewModel/Model or a hybrid as used by the Prism examples?
I have seen many people implementing
INotifyPropertyChangeddirectly in theirModeland similarly I have seen people doing it inViewModelas well.I prefer and do this(implement
INotifyPropertyChanged) inViewModel. I agree with you it sometimes create redundancy inViewModelbut I prefer a clear distinction/separatation betweenViewModelandModeland what their purpose should be. To meModelis just literally aModel. It is just representation of myBusiness Datanothing more nothing less. To me it should not cause any change inView(through notify property changed event).Viewshould talk toViewModelandViewModelshould useModel. I don’t like View directly affecting theModel. I don’t like usingModel.FirstNamebecause to me it seems like going againstMMVMby tellingViewwhat is inModel