Tag Archives: Dependency Property

Dependency Property ReSharper Live Template

Dependency Property ReSharper Live Template

Don’t you love Dependency Properties?

After the ease of automatic properties though, dependency properties are a chore to define.

If you’ve got ReSharper (if not, why not?), I’ve got a simple Live Template you can use to create your dependency properties.

I’ve set it up to use the dp keyword.

Here it is in use. Typing dp first to pop up the template:

image

Hitting tab or enter will run the template, with the name macro already selected:

image

Type in the name of the property. This will set up the wrapper property with that name, and the dependency property’s name will be the name you chose, with “Property” added to the end.

For example, I type in MyCaption as the property name:

image

Hitting tab shifts me to the next macro, which is the type for the dependency property:

image

My property will be of type string, so typing that in will bring up string in the suggestions. Hitting tab will select this; hitting tab again will confirm this as my type, and select the next and last macro, the owner type:

image

This will automatically be set to the name of the containing type anyway, so you can normally leave this as is; hit tab one more time and you’re done.