“{x:Static}"是什么意思?在 XAML 中是什么意思? [英] What does "{x:Static}" mean in XAML?

查看:57
本文介绍了“{x:Static}"是什么意思?在 XAML 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{x:Static} 在 XAML 中是什么意思?

What does {x:Static} mean in XAML?

代码示例:

<SolidColorBrush Color="{x:Static SystemColors.ControlColor}" />

推荐答案

这是一种将任何静态值插入到 XAML 中的方法.例如,如果我有一个类:

It is a way to insert any static value into XAML. For example, if I have a class:

namespace A 
{ 
    public class MyConstants 
    {
        public static readonly string SomeConstantString = "BAM!";
    }
}

我可以像这样使用 XAML 将它放入 WPF UI 中:

I can place it into a WPF UI using XAML like this:

<TextBlock Text="{x:Static A:MyConstants.SomeConstantString}" />

请注意,您必须将定义 MyConstants 的命名空间导入 XAML.所以在 or 元素中做一些类似的事情:

Notice, you will have to import the namespace in which MyConstants is defined into your XAML. So in the or element do something like:

xmlns:A="clr-namespace:A"

这篇关于“{x:Static}"是什么意思?在 XAML 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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