Tip: quickly create a dependency property

If you want to make a property that can be styled from XAML - you need to create a dependency property on your control.  This can be a tricky syntax, but fortunately the C#/VB editor have "snippets" that allow you to really quickly create one.

Let’s assume we’re creating a BorderVisibility property on a UserControl.  It defaults to Visibility.Hidden.

Right click on the code editor.
Choose “Insert Snippet ...”
Choose NetFX30>Define a Dependency Property

Tab through and replace the fields in green. 

Replace the following:

·         int with our return type: Visibility

·         ownerclass with the class that defines the property, e.g. UserControl1

·         0 with the default value for the property Visibility.Hidden

Comments (0)

Skip to main content