An explicit style is a .NET MAUI style identified by an x:Key and applied selectively through a control’s Style property. It groups Setters for a target control type, letting specific views share coordinated property values without changing every instance. section 10.1.1
Use an explicit style when:
- Only selected instances of a control should receive the visual customization. section 10.4
- Several properties should be kept together, such as font size, alignment, and text color. section 10.1.1
- A specific style must take precedence over app-wide, page-specific, or control-level styles. section 10.4
Styling a count label
Define a keyed style for Label controls: <Style TargetType="Label" x:Key="CountLabelStyle"><Setter Property="FontSize" Value="64"/><Setter Property="HorizontalOptions" Value="Center"/><Setter Property="VerticalOptions" Value="Center"/><Setter Property="TextColor" Value="{StaticResource Primary}"/></Style>. Apply it only where needed with Style="{StaticResource CountLabelStyle}" on the count Label. section 10.1.1
Listing 10.3 The CountLabelStyle style
<Style TargetType="Label" x:Key="CountLabelStyle">
<Setter Property="FontSize" Value="64"/>
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="TextColor" Value="{StaticResource Primary}"/>
</Style>
Inspect the complete CountLabelStyle definition, including its target type, key, and property setters. section 10.1.1
<Label Grid.Row="2"
Text="{Binding Count}"
Style="{StaticResource CountLabelStyle}"/>
Inspect the XAML usage that applies CountLabelStyle to one Label through StaticResource. section 10.1.1
