无法将属性'[attr]'中的值转换为'System.Windows.TemplateBindingExtension'类型的对象

时间:2010-04-09 14:02:44

标签: wpf attached-properties templatebinding

当我在类层次结构之外的类中定义附加的依赖项属性并将所有者设置为公共父类时,我收到此错误。

WindowBase类中的附加依赖项属性(类层次结构=>生成错误之外):

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

失败的TemplateBinding

{TemplateBinding local:WindowBase.AreaColor}

如果我在类heirarchy中的类中定义附加的依赖属性并将所有者设置为此类,那么我没有得到任何错误,为什么会这样?

WindowBase中的附加依赖属性(在类层次结构中=>没有错误):

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

最诚挚的问候, 的Jesper

1 个答案:

答案 0 :(得分:2)

我通过切换到相对源绑定解决了这个问题:

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