ReSharper Live Template for Dependency Properties (C#)

The syntax for declaring WPF dependency properties can get a little tedious to type. I ended up creating a ReSharper Live Template which has been working nicely for me:

public static readonly DependencyProperty $PropertyName$Property = 
    DependencyProperty.Register("$PropertyName$", typeof($PropertyType$), typeof($PropertyOwner$));

public $PropertyType$ $PropertyName$ {
    get { return ($PropertyType$) GetValue($PropertyName$Property); }
    set { SetValue($PropertyName$Property, value); }
}

Then configure the substitutable variables as follows:

  • PropertyName, no macro, #3 editable
  • PropertyType, Guess type expected at this point, #2 editable
  • PropertyOwner, Containing type name, not editable

This lets me type in dp and fill in the blanks. Hope this helps. :)

Comments