Last active
August 29, 2015 14:11
-
-
Save Fireforge/20033701aae6423d93f5 to your computer and use it in GitHub Desktop.
Intelligent boilerplate for INotifyPropertyChanged, mostly taken from http://stackoverflow.com/a/1316417
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
#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