I was tutoring someone about DependencyProperty.aspx when I realized what a bad name this is. The dependency thing makes them sound wimpish when in fact they are strong. With me, you can use the terms SuperProperty and DependencyProperty interchangeably.
I realized that for Silverlight Dps there isn’t a good built-in snippet. I should say that this is at least not one that I know of. Without a snippet, who is going to bother to create a DP?
A good snippet library makes for good code
I’m a snippet enthusiast or you could say that I’m a fanatic. I think a good snipper library makes for good code – making it consistent. It encourages you to do things the right way even if that right way requires plenty of code.
I’m such a snippet fan, and in fact, at MIX last year I devoted my talk to the subject. A lot of the snippets however from the talk have become stale. I’ve been building out a new library and for WPF, I use Dr. WPF’s indispensable snippets. I’ve been slowly building up a new library for Silverlight.
Because I haven’t been able to find much, I’m sharing mine. If you’re new to VS snippets, you can get info here. To use them, you just install the .vsi and then type the snippet shortcut. You then tap the tab and provide the values it asks for and hit enter.
Remember that when you provide a default value for a double, you need to include the decimal so that the compiler doesn’t treat it like an int but a double.
Silverlight is a platform for building rich internet applications. Snippets are able to add some vibrancy to your editor. Snippets out the box are supported by most code editors. Also, you are able to use snippets globally.
These snippets are templates that can be inserted into a document by command or through some trigger text.
You can create a boilerplate file with snippets and insert commonly used blocks of text. The idea is to save you typing out the same stuff over and over again.
These snippets can be categorized according to interactivity between the snippet and the editor. There are all kinds of snippets, from dynamic snippets to macro snippets to static snippets. Snippets have evolved over the years to better meet the needs of Silverlight and WPF.
One thing that confuses people about Silverlight is the concept of dependency properties. While you can use standard CLR properties in Silverlight applications, Silverlight relies on dependency properties.
Dependency properties are an essential part of the template, style, and data binding in Silverlight. If you want to bind data to property and transform it in XAML then the property involved has to be a dependency property if it’s to work properly.
Any property that you bind or transform must be a dependency property in Silverlight applications.