Skip to content

Instantly share code, notes, and snippets.

@tuneis
Last active March 6, 2017 18:49
Show Gist options
  • Save tuneis/51218d50e4467db3a4fc9591a5ea7a5e to your computer and use it in GitHub Desktop.
Save tuneis/51218d50e4467db3a4fc9591a5ea7a5e to your computer and use it in GitHub Desktop.
BaseViewModel
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