Skip to content

Instantly share code, notes, and snippets.

@runceel

runceel/Explain.cs

Last active Nov 30, 2020
Embed
What would you like to do?
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