访问XAML中的静态字段

时间:2008-08-28 14:24:15

标签: c# .net wpf silverlight xaml

如何在xaml中引用类的静态属性?换句话说,我想做这样的事情:

Class BaseThingy {
  public static readonly Style BaseStyle;
  ...
}
<ResoureDictionary ...>
  <Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" />
</ResourceDictionary>

在BasedOn中执行此操作的语法是什么?我认为它会涉及在某种程度上使用StaticResource,但我还没有让它为我工作。

1 个答案:

答案 0 :(得分: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>