Cannot convert the value in attribute '[attr]' to object of type 'System.Windows.TemplateBindingExtension'

StackOverflow https://stackoverflow.com/questions/2608082

Question

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

Was it helpful?

Solution

I solved the issue by switching to relative source binding:

{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=(Window.CaseAreaColor)}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top