不能在属性“[ATTR]”值转换为类型的对象“System.Windows.TemplateBindingExtension”

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

当我在类层次之外的类定义我附依赖特性和所有者设置到公共的父类我得到这个错误。

在WindowBase类附加依赖属性(外侧类层次=>生成的错误):

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

TemplateBinding失败

{TemplateBinding local:WindowBase.AreaColor}

如果我不是在类层次结构中的类定义附加依赖项属性和业主设置为此类的话,我没有得到任何错误,这是为什么?

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

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

此致 的Jesper

有帮助吗?

解决方案

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

{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=(Window.CaseAreaColor)}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top