Skip to content

Instantly share code, notes, and snippets.

@Fireforge
Last active August 29, 2015 14:11
Show Gist options
  • Save Fireforge/20033701aae6423d93f5 to your computer and use it in GitHub Desktop.
Save Fireforge/20033701aae6423d93f5 to your computer and use it in GitHub Desktop.
Intelligent boilerplate for INotifyPropertyChanged, mostly taken from http://stackoverflow.com/a/1316417
#region INotifyPropertyChanged Boilerplate
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propname)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propname));
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
RaisePropertyChanged(propertyName);
return true;
}
#endregion
// Minimum Binding Prop
private string _Name;
public string Name
{
get { return _Name; }
set { SetField(ref _Name, value); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment