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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With