Back to results for “XAML & Markup Extensions”
.NET MAUI › XAML & Markup Extensions

What is x:Static and when do you use it?

Intermediate

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.

Common follow-ups: x:Static vs StaticResource? | Can it reference enums?