views:

155

answers:

1

Hi,

I get this error when I define my attached dependency properties in a class outside the class hierarchy and set the owner to a common parent class.

Attached dependency property in WindowBase class (outside class hierarchy => generated error):

public static readonly DependencyProperty AreaColorProperty =
DependencyProperty.RegisterAttached("AreaColor", typeof(AreaColor), typeof(Window));

TemplateBinding that fails

{TemplateBinding local:WindowBase.AreaColor}

If I instead define the attached dependency property in a class within the class heirarchy and set the owner to this class, then I don't get any errors, why is this?

Attached dependency property in WindowBase (within class hierarchy => no errors):

public static readonly DependencyProperty AreaColorProperty =
DependencyProperty.RegisterAttached("AreaColor", typeof(AreaColor), typeof(WindowBase));

Best Regards, Jesper

+1  A: 

I solved the issue by switching to relative source binding:

{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=(Window.CaseAreaColor)}
Krimson