Create a gist now

Instantly share code, notes, and snippets.

public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate {};
string _name;
public string Name
{
get { return _name; }
set
{
if (_name == value) return
_name = value;
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
}
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate {};
string _name;
public string Name
{
get { return _name; }
set
{
if (_name == value) return
_name = value;
RaiseNotifyPropertyChanged();
}
}
void RaiseNotifyPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
public class MyViewModel : NotifyPropertyChanged
{
string _name;
public string Name
{
get { return _name; }
set
{
if (_name == value) return
_name = value;
RaiseNotifyPropertyChanged();
}
}
}
// This is utility code that you could share with the world.
abstract class NotifyPropertyChanged : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate {};
void RaiseNotifyPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment