Skip to content

BaseViewModel

Artem Kirgizov edited this page May 31, 2021 · 5 revisions

BaseViewModel - an abstract class that implements the INotifyPropertyChanged interface. It is primarily intended for inheritance by classes representing the ViewModel wrapper in WPF and UWP.

The main features of the class:

private string someProperty;

public string SomeProperty
{
    get => someProperty;
    set
    {
        someProperty = value;
        OnPropertyChanged(); // no need to specify a method name like OnPropertyChanged(nameof(SomeProperty));
    }
}
private string someProperty;

public string SomeProperty
{
    get => someProperty;
    set => SetProperty(ref someProperty, value); // the call to OnPropertyChanged () is encapsulated inside the method
}