Is it generally desirable to implement INotifyPropertyChanged on Model classes, ViewModel classes, or both? Is it possible to implement on Model only ,not on Viewmodel? If not possible model then why
-
If you're using non-`OneTime` bindings, your viewmodels **have to** implement `INotifyPropertyChanged`, or you'll get [memory leaks](https://support.microsoft.com/en-us/kb/938416). – dymanoid Sep 10 '15 at 08:20
3 Answers
Basic rule is - There is no hard and fast of any architecture, you can modify things to suit your needs that's why some architectures are more desirable.
for your exact needs go through this
and in this discussion, there are enough points to cover both arguments, see which one matches your project..
this might help you to implement..
You must understand the meaning of INotifyPropertyChanged. It's purpose is to raise notification from target to source when you define Binding in WPF. DependencyProperty and INotifyPropertyChanged are related for autoupdation for the concept of binding. If you need to bind the property on a viewmodel to view you have to implement a notification mechanism to notify to UI if there is change in Viewmodel. Same rule is applied for model to View.
Suppose you want to code in .CS file like Viewmodel.Name =" my new name"
and expect that TextBox should display the changed name.
<TextBox Text="{Binding ViewModel.Name} "/>
Here view model need to implement INotifyPropertyChanged.
<TextBox Text="{Binding Model.Name} "/>
here model need to implement INotifyPropertyChanged
Hope it clarifies.

- 6,908
- 13
- 43
- 75
-
It's working when adding to VM. code behind logic VM vm=new VM(); vm.FName = "aa"; this.DataContext =vm; xmal logic :
VM logic: public string FName – Sudhir.net Sep 10 '15 at 06:24 -
try to add code in your question and try to explain your exact issue that might help up help u – Muds Sep 10 '15 at 07:49
It might be worth noting in this discussion that Microsoft themselves add INPC in their own models e.g. the classes automatically generated when you susbscribe to a web service. I've seen it various other places as well, including a vague recollection of it somewhere in their EF stuff. I myself add it automatically to my DAL entities using Castle Proxy so that I don't have to duplicate everything in the view model, although you can also use things like Fody etc to add it to the IL in a post-processing step.

- 15,731
- 3
- 31
- 58