What problem does it solve?
Provides clear guidance and practical patterns for implementing reliable light and dark theme support in .NET MAUI applications, preventing state loss, inconsistent colors, and runtime update issues when the system theme changes or when the user selects a custom theme.
Core Features & Use Cases
- AppThemeBinding for OS-driven themes: use AppThemeBinding to automatically adapt UI values to system light or dark mode with minimal code.
- ResourceDictionary swapping for custom themes: define separate ResourceDictionary theme files and swap them at runtime to support branded themes or more than two themes, ensuring UI updates by using DynamicResource.
- Runtime APIs and gotchas: read the current theme via Application.Current.RequestedTheme, force or reset via Application.Current.UserAppTheme, respond to RequestedThemeChanged events, and use SetAppThemeColor helpers; on Android ensure MainActivity includes ConfigChanges.UiMode to receive theme change events; note that CSS-based themes cannot be swapped at runtime.
Quick Start
Enable Android UiMode in MainActivity, prefer AppThemeBinding for automatic OS support, and implement ResourceDictionary swapping with DynamicResource to achieve runtime theme switching.