| MAUI-CollectionView | MAUI-Databinding | |
.NET MAUI Styles and Resources |
In .NET MAUI (2026), Styles and Resources are the primary mechanism for creating consistent, reusable user interfaces across Android, iOS, macOS, and Windows. By grouping property values into a single object, you can reduce repetitive markup and manage global appearance changes from a single location.
Resources are reusable objects stored in a ResourceDictionary. They can include colors, brushes, fonts, numbers (e.g., Thickness), and most importantly, styles.
Where you define a resource determines its availability:
<Application.Resources>
<Color x:Key="PrimaryColor">#3498db</Color>
<FontFamily x:Key="AppFont">OpenSans-Regular</FontFamily>
</Application.Resources>
<Label Text="Hello MAUI!"
TextColor="{StaticResource PrimaryColor}"
FontFamily="{StaticResource AppFont}" />
A Style consists of a TargetType and one or more Setters, each assigning a Value to a specific Property. A Style is a collection of property setters that can be applied to controls to keep UI consistent.
<Application.Resources>
<Style TargetType="Label">
<Setter Property="TextColor" Value="DarkBlue" />
<Setter Property="FontSize" Value="18" />
</Style>
</Application.Resources>
<Label Text="This label uses the default style" />
Here, all Label controls automatically use the defined style.
<Application.Resources>
<Style x:Key="TitleLabelStyle" TargetType="Label">
<Setter Property="FontSize" Value="24" />
<Setter Property="TextColor" Value="Red" />
</Style>
</Application.Resources>
<Label Text="Title" Style="{StaticResource TitleLabelStyle}" />
For large projects, you can split resources into separate files.
Colors.xaml
<ResourceDictionary>
<Color x:Key="PrimaryColor">#2ecc71</Color>
</ResourceDictionary>
App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<Application.Resources>
<Color x:Key="BackgroundColorLight">White</Color>
<Color x:Key="BackgroundColorDark">Black</Color>
</Application.Resources>
<ContentPage BackgroundColor="{DynamicResource BackgroundColorLight}" />
You can swap the resource dictionary at runtime to switch themes.
| MAUI-CollectionView | MAUI-Databinding | |