【发布时间】:2010-04-09 14:02:43
【问题描述】:
当我在类层次结构之外的类中定义附加的依赖项属性并将所有者设置为公共父类时,出现此错误。
WindowBase 类中的附加依赖属性(在类层次结构之外 => 生成错误):
public static readonly DependencyProperty AreaColorProperty =
DependencyProperty.RegisterAttached("AreaColor", typeof(AreaColor), typeof(Window));
模板绑定失败
{TemplateBinding local:WindowBase.AreaColor}
如果我改为在类层次结构中的类中定义附加的依赖属性并将所有者设置为该类,那么我不会收到任何错误,这是为什么呢?
WindowBase 中的附加依赖属性(在类层次结构内 => 没有错误):
public static readonly DependencyProperty AreaColorProperty =
DependencyProperty.RegisterAttached("AreaColor", typeof(AreaColor), typeof(WindowBase));
最好的问候, 杰斯珀
【问题讨论】:
-
当然问题是 TemplateBinding 应该是:{TemplateBinding Window.AreaColor}。虽然这产生了一个新错误:在类型 Window 上找不到静态成员“AreaColorProperty”。然后我可以通过在 TemplateBinding 上指定一个转换器来解决这个问题...嗯
标签: wpf attached-properties templatebinding