Instantly share code, notes, and snippets.

What would you like to do?
Visual Studio 2017 Code Snippet INotifyPropertyChanged
public static void OnPropertyChanged<T>(
this INotifyPropertyChanged @this,
PropertyChangedEventHandler propertyChanged,
Expression<Func<T>> propertyExpr)
if (propertyChanged == null) return;
var memberExpr = (MemberExpression)propertyExpr.Body;
var ea = new PropertyChangedEventArgs(memberExpr.Member.Name);
propertyChanged(@this, ea);
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="">
<CodeSnippet Format="1.0.0">
<Description>Code snippet for a property that calls OnPropertyChanged() in the setter (to assist in INotifyPropertyChanged implementation).</Description>
<Author>Aaron Hoffman</Author>
<ToolTip>Property type</ToolTip>
<ToolTip>Property name</ToolTip>
<Code Language="csharp"><![CDATA[public $type$ $property$
get { return _$property$; }
if (_$property$ != value)
_$property$ = value;
this.OnPropertyChanged(PropertyChanged, () => $property$);
private $type$ _$property$;$end$]]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment