Skip to content

Instantly share code, notes, and snippets.

@timheuer
Created May 22, 2012 15:59
Show Gist options
  • Save timheuer/2769949 to your computer and use it in GitHub Desktop.
Save timheuer/2769949 to your computer and use it in GitHub Desktop.
Base View Model (simple)
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace App1
{
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void SetValue<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
{
if (object.Equals(storage, value)) { return; }
storage = value;
RaisePropertyChanged(propertyName);
}
void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment