Before we create an actual view model, 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:
- In the GalleryApp project, create a folder named ViewModels.
- Create a new abstract class named ViewModel:
public abstract class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void Set<T>(ref T field, T newValue, [CallerMemberName]
string propertyName = null)
{
if (!EqualityComparer<T>.Default.Equals(field, newValue))
{
field = newValue;
RaisePropertyChanged(propertyName);
}
}
protected void RaisePropertyChanged([CallerMemberName] string
propertyName = null)
{
PropertyChanged?.Invoke...