I read lots of articles, And found that lots of people use INotifyPropertyChanged in ViewModel either Model as well. So, I am confused about INotifyPropertyChanged where to use.
Asked
Active
Viewed 92 times
0
-
1possible duplicate of [In MVVM should the ViewModel or Model implement INotifyPropertyChanged?](http://stackoverflow.com/questions/772214/in-mvvm-should-the-viewmodel-or-model-implement-inotifypropertychanged) – C Bauer Oct 15 '14 at 11:56
1 Answers
0
A popular approach is to use a base class which Implements InotifyPropertyChanged interface and then inherit this base class in your View Model.
example:
public class NotifyPropertyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Then inherit the base class in the view model:
class MainViewModel : NotifyPropertyBase
Finally, raise the OnPropertyChanged event in the property setter of your view model passing in the property name string as the parameter:
private string _name;
public string Name
{
get { return _name; }
set
{
_name= value;
OnPropertyChanged("Name");
}
}
Now your UI should update at run time provided the binding is declared correctly in the Xaml.

Hardgraf
- 2,566
- 4
- 44
- 77