ReSharper C# Live Template for Dependency Property and Property Change Routed Event Boilerplate Code

I don’t know about you but it took me about 5 seconds to get royally fed up of typing the boilerplate code necessary for creating WPF (and Silverlight) dependency properties and, if you want them, their associated property change routed events.

Being a ReSharper user, I wondered if there was any live template for doing this. It turns out there’s nothing built in, but there are many examples of templates for creating dependency properties out there on the web, such as this excellent one from Roy Osherove, on which my template below is based.

Today, in addition to the properties themselves, I wanted something that would also create associated routed event boilerplate for me as well. I’ve no doubt there are already loads of these out there as well but our Internet connection’s been down or unusably slow for most of the afternoon so I ended up writing my own, and thought there was no harm in sharing it.

Please feel free to use and abuse it as you see fit. I’m using ReSharper 5 in Visual Studio 2010, but this should work fine in earlier versions as well. On my system I’ve set it so that it’ll only be available in C# files where member declaration is valid, but you don’t really need to do this (although it probably won’t be very useful anywhere else).