In MVVM model should the model implement INotifyPropertyChanged interface?

Viewed 26916

I have clear idea about View and ViewModel in MVVM pattern. I am planning to implement MVVM pattern in my application. I'm facing an issue regarding the model. I have .xml file which is parsed and the information is displayed in the View.

I need to be notified about the changes in the model for the first time only. From onwards on demand I need to be notified.

So how to implement the model?

Should I implement INotifyPropertyChanged interface in model class also? (I read that model should not implement INotifyPropertyChanged interface, since it is WPF specific)

6 Answers

This is a classic argument between the "pure" MVVM coders and others.

I tend to go by the books whenever I can because most of the times that makes sense. However, in certain scenarios improvising the code according to the needs reduce a lot of duplicate code.

In your case, you can read the XML to a model class and either make a copy of the model class to the viewmodel, or copy the properties you want from the model to the view model. This way you have control for updating the UI/model. If you follow the first approach you need to have Inotifypropertychanged implemetned in your model class and it is acceptable.

Having said that I would try my level best to follow the second approach because that would give me precise control over all the properties which is displayed/manipulated in the view. Also, I will feel much better that I am not breaking the MVVM pattern.

Related