访问在XAML静态字段 [英] Accessing static fields in XAML

查看:201
本文介绍了访问在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>

什么是语法要做到这一点,在支持算法FMP?我以为这会涉及使用的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆