Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "{x:Static}" mean in XAML?

Tags:

.net

wpf

xaml

People also ask

What is X static XAML?

x:Static is a markup extension. All markup extensions in XAML use the { and } characters in their attribute syntax, which is the convention by which a XAML processor recognizes that a markup extension must provide a value.

What is X class XAML?

Configures XAML compilation to join partial classes between markup and code-behind. The code partial class is defined in a separate code file in a CLR language, and the markup partial class is created by code generation during XAML compilation.

What is X type in WPF?

WPF supports techniques that enable specifying the value of some properties of type Type without requiring an x:Type markup extension usage. Instead, you can specify the value as a string that names the type. Examples of this are ControlTemplate. TargetType and Style.

What is static resource in WPF?

Static Resource - Static resources are the resources which you cannot manipulate at runtime. The static resources are evaluated only once by the element which refers them during the loading of 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!";
    }
}

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"

From MSDN: http://msdn.microsoft.com/en-us/library/ms742135.aspx

References any static by-value code entity defined in a Common Language Specification (CLS) compliant way The property referenced is evaluated prior to loading the remainder of the XAML page and can be used to provide the value of a property in XAML.