Skip to content

Instantly share code, notes, and snippets.

@sidwarkd
Created May 11, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidwarkd/4e06afeae798bb758aed5c3952fa49e2 to your computer and use it in GitHub Desktop.
Save sidwarkd/4e06afeae798bb758aed5c3952fa49e2 to your computer and use it in GitHub Desktop.
Observable Class for UWP Data Binding
public class Observable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void Changed([CallerMemberName]string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
protected void SetProperty<T>(ref T field, T val, [CallerMemberName]string propertyName = null)
{
if (object.Equals(field, val)) return;
field = val;
Changed(propertyName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment