As background here's how register an attached property
public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterAttached(
"IsBubbleSource",
typeof(Boolean),
typeof(AquariumObject),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)
);
public static void SetIsBubbleSource(UIElement element, Boolean value)
{
element.SetValue(IsBubbleSourceProperty, value);
}
public static Boolean GetIsBubbleSource(UIElement element)
{
return (Boolean)element.GetValue(IsBubbleSourceProperty);
}
You can also use a standard property format rather than the Set/Get construct. This is one of those areas where WPF has a strong convention in place. There are three parts of an AttachedProperty
(or any DependencyProperty
). The first is registering the property with DependencyProperty.RegisterAttached
and the return value should be set to a public static variable named [Property Name]Property. The second is that the first argument when registering your property should be "[Property Name]". And the third is the Get/Set methods you'll use to interact with the outside world which should be named Get[Property Name], Set[Property Name].
If you set it up according to the convention WPF will recognize that the two are connected and should allow you to use the property as you expect.