Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What does {x:Static} mean in XAML?

Code sample:

<SolidColorBrush Color="{x:Static SystemColors.ControlColor}" />
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
337 views
Welcome To Ask or Share your Answers For Others

1 Answer

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!";
    }
}

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

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

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...