If you create a type that defines an attached property, you will notice that this attached property does not show up in the WPF Designer (Cider) Property Browser. So how do you get it to show up and what level of control do you have over when it shows up?
As it turns out, you can use the following attributes to control how your properties show up in the Property Browser:
You apply them to the get accessor of your attached property definition, like this:
public class WhenAttributePresentTestControl : Grid
public static readonly DependencyProperty ShowWhenCustomAttributePresentProperty = DependencyProperty.RegisterAttached(
public static void SetShowWhenCustomAttributePresent(UIElement element, int value)
public static int GetShowWhenCustomAttributePresent(UIElement element)
One thing to keep in mind is that one of the requirements of showing attached properties in the designer is that the owning type needs to have been loaded by the designer. This happens whenever the designer accesses the type because it is in the XAML source or is a dependency of an element loaded from the XAML source.
Attached to this post is an example of using all 3 of these attributes.
This attribute allows you to specify that your attached property show up in the Property Browser when the selected item has a given attribute applied to it. If the attribute has a default value, that value also has to be different from the default value.
In the example above that passes in “MyCustomAttribute” as the attribute to look for, when CustomLabel below is selected in the designer, the Property Browser will show the ShowWhenCustomAttribute attached property however it will not when CustomLabelNoCustomAttribute is selected:
public class CustomLabel : Label
public class CustomLabelNoCustomAttribute : Label
This attribute indicates that the attached property should be available for the children of the given control. There are two main flavors for this attribute. One that includes descendants and one that does not. As you might expect including descendants refers to including all children or simply the direct children of the control.
public static int GetShowForChildrenDeep(UIElement element)
This attribute allows you to specify that your attached property show up when a given type or types derived from that type are selected in the designer. The following sample would make your attached property show up when any Grid, derived Grid, Button or derived Button is selected.
public static int GetShowForTypes(UIElement element)
I have attached a sample to this blog post the shows the usage of all the attributes listed above in the Cider WPF Designer.