访问 XAML 中的静态字段 [英] Accessing static fields in XAML
本文介绍了访问 XAML 中的静态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 xaml 中引用类的静态属性?换句话说,我想做这样的事情:
How does one go about referencing a class's static properties in xaml? In other words, I want to do something like this:
Class BaseThingy {
public static readonly Style BaseStyle;
...
}
<ResoureDictionary ...>
<Style BasedOn="BaseThingy.Style" TargetType="BaseThingy" />
</ResourceDictionary>
在BasedOn 中执行此操作的语法是什么?我认为它会在某种程度上涉及使用 StaticResource
,但我还没有让它为我工作.
What is the syntax to do this in the BasedOn? I assumed it would involve using StaticResource
to some degree, but I haven't gotten it to work for me.
推荐答案
使用 x:静态标记扩展
<ResoureDictionary ...
xmlns:local="clr-namespace:Namespace.Where.Your.BaseThingy.Class.Is.Defined"
>
<Style BasedOn="{x:Static local:BaseThingy.BaseStyle}" TargetType="BaseThingy" />
</ResourceDictionary>
这篇关于访问 XAML 中的静态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文