100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Styling and Resources

How ResourceDictionary scoping, implicit/explicit Styles, BasedOn inheritance, and AppThemeBinding/DynamicResource combine to theme a MAUI app.

UI & LayoutsIntermediate9 min readJul 10, 2026
Analogies

Styles and the Resource Hierarchy

MAUI styling centers on ResourceDictionary objects that hold reusable values — Style, Color, double, DataTemplate — keyed by an x:Key and scoped at the application (App.xaml), page, or control level, with resource lookup walking up from the requesting element through its visual tree ancestors until it reaches App.Resources, similar to CSS cascade but resolved at XAML parse/load time rather than continuously.

🏏

Cricket analogy: Resource lookup walking up the visual tree to App.Resources is like an umpire's decision escalating from on-field call to third umpire to the match referee when the local ruling isn't defined, ending at the tournament's overarching rulebook.

Implicit vs Explicit Styles and Style Inheritance

A Style targets a specific TargetType (e.g., TargetType='Button') and can be implicit — applied automatically to every control of that type in scope when it has no x:Key — or explicit, applied only when a control sets Style='{StaticResource MyButtonStyle}'. Styles support BasedOn to inherit setters from a parent style and override specific ones, mirroring object-oriented inheritance, and each Setter specifies a Property and Value pair that gets applied when the style resolves.

🏏

Cricket analogy: An implicit Style with no x:Key applying to every Button automatically is like a ground's standard pitch preparation applied to every match, while BasedOn is a curator adjusting that standard prep with extra grass for a pace-friendly fixture.

xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Style TargetType="Button" x:Key="BaseButtonStyle">
        <Setter Property="CornerRadius" Value="8" />
        <Setter Property="Padding" Value="16,10" />
        <Setter Property="FontFamily" Value="OpenSansRegular" />
    </Style>

    <Style TargetType="Button" x:Key="DangerButtonStyle" BasedOn="{StaticResource BaseButtonStyle}">
        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=#D32F2F, Dark=#B71C1C}" />
        <Setter Property="TextColor" Value="White" />
    </Style>

    <Style TargetType="Label">
        <Setter Property="TextColor" Value="{AppThemeBinding Light=Black, Dark=White}" />
    </Style>
</ResourceDictionary>

Themes with AppThemeBinding and Dynamic Resources

AppThemeBinding lets a single property switch value based on the active AppTheme (Light or Dark) detected via Application.Current.RequestedTheme, commonly written as {AppThemeBinding Light=White, Dark=Black}, while DynamicResource (unlike StaticResource) keeps a live link to the resource dictionary entry so that if the resource value changes at runtime — for example when a user manually switches themes — every bound control updates immediately without an app restart.

🏏

Cricket analogy: AppThemeBinding switching colors between Light and Dark is like day and day-night Test matches switching the ball color from red to pink automatically based on the match format detected.

Use MergedDictionaries to split large style catalogs into focused files — Colors.xaml, Fonts.xaml, Styles.xaml — then merge them into App.Resources in App.xaml. This keeps each dictionary maintainable and lets you swap an entire theme file (e.g., DarkTheme.xaml) by changing the merge, rather than editing dozens of inline color values.

  • ResourceDictionary values cascade from control to page to App.Resources
  • Implicit styles need no x:Key; explicit styles require a StaticResource reference
  • BasedOn allows style inheritance with targeted setter overrides
  • AppThemeBinding switches values automatically based on Light/Dark theme
  • DynamicResource keeps a live binding that updates at runtime; StaticResource does not
  • MergedDictionaries combine multiple style/color/font files into one App.Resources
  • Application.Current.UserAppTheme lets users override the OS-level theme

Practice what you learned

Was this page helpful?

Topics covered

#Programming#NETMAUIStudyNotes#StylingAndResources#Styling#Resources#Styles#Resource#StudyNotes#SkillVeris#ExamPrep