Aller au contenu
Skillpedia
Applis mobiles5.8k · #14589

maui-theming

Ce qu’il fait

Cette skill guide la gestion des thèmes dans les apps .NET MAUI, y compris les modes clair et sombre et les thèmes de couleurs personnalisés. Elle s'adresse aux développeurs qui veulent que leur app suive le thème du système ou laisse l'utilisateur le choisir.

Quand l’utiliser

  • ✓Quand vous voulez qu'une app .NET MAUI prenne en charge les modes clair et sombre.
  • ✓Quand vous voulez changer de thème à l'exécution ou laisser l'utilisateur en choisir un.
  • ✓Quand vous voulez un thème de couleurs de marque configuré avec des dictionnaires de ressources.

Lien du skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-theming/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-theming/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Ajoute le mode sombre à mon app MAUI et laisse l'utilisateur choisir clair, sombre ou système dans les réglages.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'agent utilise des liaisons de thème pour des couleurs claires et sombres simples, ou remplace des dictionnaires de ressources pour des thèmes personnalisés, et réagit au thème du système comme au choix de l'utilisateur.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

.NET MAUI Theming

Apply light/dark mode support, custom branded themes, and runtime theme switching in .NET MAUI apps using AppThemeBinding, ResourceDictionary swapping, and system theme detection APIs.

When to Use

  • Adding light and dark mode support to a .NET MAUI app
  • Creating custom branded themes with ResourceDictionary
  • Detecting and responding to system theme changes at runtime
  • Letting users choose a preferred theme (light, dark, or system default)
  • Combining OS-driven theme response with custom color palettes

When Not to Use

Inputs

  • A .NET MAUI project targeting .NET 8 or later
  • XAML pages or C# UI code that need theme-aware styling

Workflow

  1. Detect the current theme approach in the project (AppThemeBinding, ResourceDictionary, or none).
  2. Choose the appropriate strategy: AppThemeBinding for simple light/dark, ResourceDictionary swap for custom/multiple themes, or both combined.
  3. Define theme resources — inline AppThemeBinding values or separate ResourceDictionary files with matching keys.
  4. Replace hardcoded colors with DynamicResource bindings (or AppThemeBinding markup) throughout XAML pages.
  5. Add system theme detection via Application.Current.RequestedTheme and the RequestedThemeChanged event.
  6. Implement user preference persistence with Preferences.Set / Preferences.Get and apply on startup.
  7. Verify Android ConfigChanges.UiMode is set on MainActivity to avoid activity restarts on theme change.
  8. Test both light and dark themes on at least one target platform, confirming all UI elements respond correctly.

Rules That Change the Answer

Check these rules against the user's scenario, and apply only the ones that affect what they asked. UiMode and dictionary swapping matter for runtime theme switching; they are noise in a question about setting up AppThemeBinding.

Answer narrowly, but completely. Completeness means showing the code that implements what you recommended — not adding adjacent topics. If you recommend DynamicResource, show the dictionary swap that makes it update. If the user asks for light/dark colours in C#, show both SetAppThemeColor (colours) and the generic SetAppTheme<T> (any bindable property type), and prefer resource keys over scattered hardcoded colours. Do not tack on platform configuration the question didn't raise.

Rule Do this Not this Why
Runtime-swapped values must be dynamic {DynamicResource Key} {StaticResource Key} StaticResource resolves once at load and never updates when dictionaries are swapped.
Android must declare UiMode (only for runtime/system theme switching) Include ConfigChanges.UiMode in the ConfigurationChanges list on MainActivity Omitting it Without it Android restarts the activity on theme change — navigation state is lost and it looks like a crash. Irrelevant to a static AppThemeBinding setup
Force a theme via UserAppTheme Application.Current.UserAppTheme = AppTheme.Dark Manually re-assigning colors UserAppTheme overrides the OS; AppTheme.Unspecified returns to following the system.

Do not replace a working AppThemeBinding setup with ResourceDictionary swapping (or vice versa) unless the user needs what the other approach provides — more than two themes, or a user-selectable theme.

Choosing an Approach

Approach Best for Limitation
AppThemeBinding Automatic light/dark with OS — minimal code Only two themes (light + dark)
ResourceDictionary swap Custom branded themes, more than two themes, user preference More setup; must use DynamicResource everywhere
Both combined OS-driven response plus custom theme colors Most flexible but most complex

AppThemeBinding (OS Light/Dark)

AppThemeBinding selects a value based on the current system theme. It supports Light, Dark,

Questions fréquentes

Suit-elle le thème du système ?

Oui. La skill couvre la réaction au thème du système comme au choix de l'utilisateur.

Couvre-t-elle la localisation ?

Non. Le changement de langue relève d'un guide séparé.

Couvre-t-elle les icônes d'app ?

Non. Les icônes d'app et les écrans de démarrage sont hors de son périmètre.

Détails

Description originale de l’auteur

Guide for theming .NET MAUI apps — light/dark mode via AppThemeBinding, ResourceDictionary theme switching, DynamicResource bindings, system theme detection, and user theme preferences. Use when: "dark mode", "light mode", "theming", "AppThemeBinding", "theme switching", "ResourceDictionary theme", "dynamic resources", "system theme detection", "color scheme", "app theme", "DynamicResource". Do not use for: localization or language switching (see .NET MAUI localization documentation), accessibility visual adjustments (see .NET MAUI accessibility documentation), app icons or splash screens (see

repo: dotnet/skills

Popularité

Étoiles GitHub
5.8k
Position au classement
#14589
Licence
MIT
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires