Before we create an actual ViewModel, we will create an abstract base view model that all view models can inherit from. The idea behind this base view model is that we can write common code in it. In this case, we will implement the INotifyPropertyChanged interface by going through the following steps:
- Create a folder called ViewModels in the MeTracker project.
- Create a new class called ViewModel.
- Write the following code and resolve all references:
public abstract class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(params string[] propertyNames)
{
foreach(var propertyName in propertyNames)
{
PropertyChanged?.Invoke(this, new
PropertyChangedEventArgs(propertyName));
}
}
}
The next step is to create the actual view model that will use ViewModel as a base class. Let's set this up by going through the...