在XAML中访问静态字段

4
如何在XAML中引用类的静态属性?换句话说,我想做这样的事情:
Class BaseThingy {
  public static readonly Style BaseStyle;
  ...
}

<ResoureDictionary ...>
  <Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" />
</ResourceDictionary>

这在BasedOn中的语法是什么?我以为这会涉及到在一定程度上使用StaticResource,但我没能做到。
1个回答

11

使用x:Static标记扩展。

<ResoureDictionary ...
  xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined"
>
  <Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" />
</ResourceDictionary>

1
我曾经认为在Silverlight中{x:Static ...}是无法工作的。 - Drew Noakes
Namespace.Where.Your.BaseThingy.Class.Is.Defined 是该类的命名空间吗? - Lance

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接