What does "{x:Static}" mean in XAML?
Code sample:
<SolidColorBrush Color="{x:Static SystemColors.ControlColor}" />
What does "{x:Static}" mean in XAML?
Code sample:
<SolidColorBrush Color="{x:Static SystemColors.ControlColor}" />
I found the answer at <http://stackoverflow.com/questions/32395/xaml-accessing-static-fields> (from the answer suggestions), which links to http://msdn.microsoft.com/en-us/library/ms742135.aspx but I figured this would still be useful as a question to have on the site.
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.
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"