代码之家  ›  专栏  ›  技术社区  ›  MojoFilter

在XAML中访问静态字段

  •  4
  • MojoFilter  · 技术社区  · 17 年前

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

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

    在BasedOn中执行此操作的语法是什么?我以为这会涉及使用 StaticResource

    1 回复  |  直到 14 年前
        1
  •  11
  •   aku    17 年前

    使用 x:Static 标记扩展

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