首页 / 知识

关于 c#:访问 XAML 中的静态字段

2023-04-13 11:59:00

关于 c#:访问 XAML 中的静态字段

Accessing static fields in XAML

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

1
2
3
4
Class BaseThingy {
  public static readonly Style BaseStyle;
  ...
}
1
2
3
ResoureDictionary ...
  Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" /
/ResourceDictionary

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


使用 x:静态标记扩展

1
2
3
4
5
ResoureDictionary ...
  xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined"

  Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" /
/ResourceDictionary


字段引用静态属性静态

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢