Skip to content

Instantly share code, notes, and snippets.

@bobbychopra
Created June 8, 2012 11:57
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 bobbychopra/2895245 to your computer and use it in GitHub Desktop.
Save bobbychopra/2895245 to your computer and use it in GitHub Desktop.
Notify Property Changed using Expression Tree
private string _filePath;
public string FilePath
{
get { return _filePath; }
set { _filePath = value; NotifyOfPropertyChange(()=> FilePath); }
}
private void NotifyOfPropertyChange<TValue>(Expression<Func<TValue>> propertySelector)
{
if (PropertyChanged != null)
{
var memberExpression = propertySelector.Body as MemberExpression;
if (memberExpression != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(memberExpression.Member.Name));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment