What is x:Static and when do you use it?
Short answer
x:Static references a static field, property, constant, or enum member from XAML, e.g., a color in a static class or an app constant. It's handy for sharing constants between C# and XAML without wrapping them in resources.
Advertisement
AModel answer
x:Static references a static field, property, constant, or enum member from XAML, e.g., a color in a static class or an app constant. It's handy for sharing constants between C# and XAML without wrapping them in resources.
<Label TextColor="{x:Static local:AppColors.Brand}"
Text="{x:Static local:AppStrings.Welcome}" />Real-world example
Brand colors and shared strings defined as C# constants are referenced directly in XAML via x:Static.
Likely follow-ups
- x:Static vs StaticResource? | Can it reference enums?
Related topics