Skip to content

Instantly share code, notes, and snippets.

@runceel
Last active November 30, 2020 09:08
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 runceel/fd7cf1b955979121ca1c351daccb674c to your computer and use it in GitHub Desktop.
Save runceel/fd7cf1b955979121ca1c351daccb674c to your computer and use it in GitHub Desktop.
class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName]string propertyName = null)
{
Debug.WriteLine("PropertyChangedが {GetType().Name} で呼ばれました。");
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
class MyViewModel : BindableBase
{
private string _name;
public string Name
{
get => _name;
set
{
Debug.WriteLine("set_Name が {GetType().Name} で呼ばれました。");
SetProperty(ref _name, value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment