Last active
March 6, 2017 18:49
-
-
Save tuneis/51218d50e4467db3a4fc9591a5ea7a5e to your computer and use it in GitHub Desktop.
BaseViewModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseViewModel : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
public void OnPropertyChanged([CallerMemberName]string propertyName = "") => | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
protected void SetValue<T>(ref T backingField, T value, [CallerMemberName]string propertyName = null) | |
{ | |
if (EqualityComparer<T>.Default.Equals(backingField, value)) | |
return; | |
backingField = value; | |
OnPropertyChanged(propertyName); | |
} | |
} | |
// set properties like this in child view models | |
private string _someProperty; | |
public string SomeProperty | |
{ | |
get { return _someProperty; } | |
set { SetValue(ref _someProperty, value); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment