[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7D1W6X23BT3J1JZ00AXPEFE":3,"skill-same:01M7D1W6X23BT3J1JZ00AXPEFE":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M7D1W6X23BT3J1JZ00AXPEFE","maui-theming",null,"Guide for theming .NET MAUI apps — light\u002Fdark 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 .NET MAUI app icons documentation), or Bootstrap-style class theming (see Plugin.Maui.BootstrapTheme NuGet package).","itsmejay18\u002FAI-Skills-for-My-Development-Stack","itsmejay18","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F167779943?v=4","01M7CZRFC6DDZA5V2CX8WDSZED","Jay Jemino Ababon ","01M7CZRFCVRNW1SFHSQXEJ3CQN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F10-Mobile-Development\u002Fmaui-theming\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: maui-theming\ndescription: >-\n  Guide for theming .NET MAUI apps — light\u002Fdark mode via AppThemeBinding,\n  ResourceDictionary theme switching, DynamicResource bindings, system theme\n  detection, and user theme preferences.\n  Use when: \"dark mode\", \"light mode\", \"theming\", \"AppThemeBinding\",\n  \"theme switching\", \"ResourceDictionary theme\", \"dynamic resources\",\n  \"system theme detection\", \"color scheme\", \"app theme\", \"DynamicResource\".\n  Do not use for: localization or language switching (see .NET MAUI localization\n  documentation), accessibility visual adjustments (see .NET MAUI accessibility\n  documentation), app icons or splash screens (see .NET MAUI app icons\n  documentation), or Bootstrap-style class theming (see Plugin.Maui.BootstrapTheme\n  NuGet package).\nlicense: MIT\n---\n\n# .NET MAUI Theming\n\nApply light\u002Fdark mode support, custom branded themes, and runtime theme switching in .NET MAUI apps using AppThemeBinding, ResourceDictionary swapping, and system theme detection APIs.\n\n## When to Use\n\n- Adding light and dark mode support to a .NET MAUI app\n- Creating custom branded themes with ResourceDictionary\n- Detecting and responding to system theme changes at runtime\n- Letting users choose a preferred theme (light, dark, or system default)\n- Combining OS-driven theme response with custom color palettes\n\n## When Not to Use\n\n- Localization or language switching — see [.NET MAUI localization docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Flocalization)\n- Accessibility-specific visual adjustments — see [.NET MAUI accessibility docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Faccessibility)\n- App icon or splash screen configuration — see [.NET MAUI app icon docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Fuser-interface\u002Fimages\u002Fapp-icons)\n- Bootstrap-style class theming — see the `Plugin.Maui.BootstrapTheme` NuGet package\n\n## Inputs\n\n- A .NET MAUI project targeting .NET 8 or later\n- XAML pages or C# UI code that need theme-aware styling\n\n## Workflow\n\n1. Detect the current theme approach in the project (AppThemeBinding, ResourceDictionary, or none).\n2. Choose the appropriate strategy: AppThemeBinding for simple light\u002Fdark, ResourceDictionary swap for custom\u002Fmultiple themes, or both combined.\n3. Define theme resources — inline `AppThemeBinding` values or separate `ResourceDictionary` files with matching keys.\n4. Replace hardcoded colors with `DynamicResource` bindings (or `AppThemeBinding` markup) throughout XAML pages.\n5. Add system theme detection via `Application.Current.RequestedTheme` and the `RequestedThemeChanged` event.\n6. Implement user preference persistence with `Preferences.Set` \u002F `Preferences.Get` and apply on startup.\n7. Verify Android `ConfigChanges.UiMode` is set on `MainActivity` to avoid activity restarts on theme change.\n8. Test both light and dark themes on at least one target platform, confirming all UI elements respond correctly.\n\n## Rules That Change the Answer\n\nCheck these rules against the user's scenario, and apply **only** the ones that\naffect what they asked. `UiMode` and dictionary swapping matter for *runtime theme\nswitching*; they are noise in a question about setting up `AppThemeBinding`.\n\n**Answer narrowly, but completely.** Completeness means showing the code that\nimplements *what you recommended* — not adding adjacent topics. If you recommend\n`DynamicResource`, show the dictionary swap that makes it update. If the user asks\nfor light\u002Fdark colours in C#, show **both** `SetAppThemeColor` (colours) and the\ngeneric `SetAppTheme\u003CT>` (any bindable property type), and prefer resource keys over\nscattered hardcoded colours. Do not tack on platform configuration the question\ndidn't raise.\n\n| Rule | Do this | Not this | Why |\n|---|---|---|---|\n| **Runtime-swapped values must be dynamic** | `{DynamicResource Key}` | `{StaticResource Key}` | `StaticResource` resolves once at load and never updates when dictionaries are swapped. |\n| **Android must declare `UiMode`** *(only for runtime\u002Fsystem 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 |\n| **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. |\n\n**Do not** replace a working `AppThemeBinding` setup with ResourceDictionary\nswapping (or vice versa) unless the user needs what the other approach provides —\nmore than two themes, or a user-selectable theme.\n\n## Choosing an Approach\n\n| Approach | Best for | Limitation |\n|----------|----------|------------|\n| **AppThemeBinding** | Automatic light\u002Fdark with OS — minimal code | Only two themes (light + dark) |\n| **ResourceDictionary swap** | Custom branded themes, more than two themes, user preference | More setup; must use `DynamicResource` everywhere |\n| **Both combined** | OS-driven response plus custom theme colors | Most flexible but most complex |\n\n## AppThemeBinding (OS Light\u002FDark)\n\n`AppThemeBinding` selects a value based on the current system theme. It supports `Light`, `Dark`, and an optional `Default` fallback.\n\n### Define the palette once — don't scatter literals\n\nPutting `{AppThemeBinding Light=#333333, Dark=#FFFFFF}` on every element is the\nsingle most common theming mistake: the palette ends up duplicated across dozens of\nfiles and cannot be changed in one place. **Recommend this shape as the final\nanswer**, not inline literals:\n\n```xml\n\u003C!-- App.xaml — one source of truth for the whole app -->\n\u003CApplication.Resources>\n    \u003CResourceDictionary>\n\n        \u003C!-- 1. Raw palette -->\n        \u003CColor x:Key=\"LightPageBackground\">#FFFFFF\u003C\u002FColor>\n        \u003CColor x:Key=\"DarkPageBackground\">#1E1E1E\u003C\u002FColor>\n        \u003CColor x:Key=\"LightPrimaryText\">#333333\u003C\u002FColor>\n        \u003CColor x:Key=\"DarkPrimaryText\">#E0E0E0\u003C\u002FColor>\n\n        \u003C!-- 2. Implicit styles bind the pair once; every page inherits them -->\n        \u003CStyle TargetType=\"ContentPage\" ApplyToDerivedTypes=\"True\">\n            \u003CSetter Property=\"BackgroundColor\"\n                    Value=\"{AppThemeBinding Light={StaticResource LightPageBackground},\n                                            Dark={StaticResource DarkPageBackground}}\" \u002F>\n        \u003C\u002FStyle>\n\n        \u003CStyle TargetType=\"Label\">\n            \u003CSetter Property=\"TextColor\"\n                    Value=\"{AppThemeBinding Light={StaticResource LightPrimaryText},\n                                            Dark={StaticResource DarkPrimaryText}}\" \u002F>\n        \u003C\u002FStyle>\n\n    \u003C\u002FResourceDictionary>\n\u003C\u002FApplication.Resources>\n```\n\nPages then need **no theming markup at all** — they pick the styles up implicitly.\nUse an inline `AppThemeBinding` only for genuine one-offs, and even then reference\n`{StaticResource}` keys rather than literal hex.\n\n### XAML (inline form, for one-offs)\n\n```xml\n\u003CLabel Text=\"Themed text\"\n       TextColor=\"{AppThemeBinding Light=Green, Dark=Red}\"\n       BackgroundColor=\"{AppThemeBinding Light=White, Dark=Black}\" \u002F>\n\n\u003C!-- With resource references — preferred over literals -->\n\u003CLabel TextColor=\"{AppThemeBinding Light={StaticResource LightPrimary},\n                                   Dark={StaticResource DarkPrimary}}\" \u002F>\n```\n\n### C# Extension Methods\n\nShow **both** when answering a \"light\u002Fdark colours in C#\" question — `SetAppThemeColor`\ncovers `Color` properties, `SetAppTheme\u003CT>` covers everything else:\n\n```csharp\nvar label = new Label();\n\n\u002F\u002F Color-specific helper\nlabel.SetAppThemeColor(Label.TextColorProperty, Colors.Green, Colors.Red);\n\n\u002F\u002F Generic helper — works for any bindable property type, not just Color\nlabel.SetAppTheme\u003CColor>(Label.TextColorProperty, Colors.Green, Colors.Red);\nlabel.SetAppTheme\u003Cdouble>(Label.FontSizeProperty, 14, 16);\n\n\u002F\u002F The BindableProperty must belong to the object you call it on —\n\u002F\u002F Image.SourceProperty goes on an Image, not a Label.\nvar image = new Image();\nimage.SetAppTheme\u003CImageSource>(Image.SourceProperty,\n    ImageSource.FromFile(\"logo_light.png\"),\n    ImageSource.FromFile(\"logo_dark.png\"));\n```\n\nPrefer defining the values as resource keys and referencing them, rather than\nscattering hardcoded colours across the codebase.\n\n## ResourceDictionary Theming (Custom Themes)\n\nUse separate `ResourceDictionary` files with matching keys to define themes, then swap them at runtime.\n\n### Step 1 — Define Theme Dictionaries\n\nWhen using compiled XAML with `x:Class` (as shown below), each dictionary needs a code-behind that calls `InitializeComponent()`. Dictionaries loaded via `Source` without `x:Class` do not need code-behind.\n\n**LightTheme.xaml**\n\n```xml\n\u003CResourceDictionary xmlns=\"http:\u002F\u002Fschemas.microsoft.com\u002Fdotnet\u002F2021\u002Fmaui\"\n                    xmlns:x=\"http:\u002F\u002Fschemas.microsoft.com\u002Fwinfx\u002F2009\u002Fxaml\"\n                    x:Class=\"MyApp.Themes.LightTheme\">\n    \u003CColor x:Key=\"PageBackgroundColor\">White\u003C\u002FColor>\n    \u003CColor x:Key=\"PrimaryTextColor\">#333333\u003C\u002FColor>\n    \u003CColor x:Key=\"AccentColor\">#2196F3\u003C\u002FColor>\n\u003C\u002FResourceDictionary>\n```\n\n**LightTheme.xaml.cs**\n\n```csharp\nnamespace MyApp.Themes;\n\npublic partial class LightTheme : ResourceDictionary\n{\n    public LightTheme() => InitializeComponent();\n}\n```\n\nCreate a matching **DarkTheme.xaml \u002F DarkTheme.xaml.cs** with the same keys and different values.\n\n### Step 2 — Consume with DynamicResource\n\nUse `DynamicResource` so values update when the dictionary is swapped at runtime:\n\n```xml\n\u003CContentPage BackgroundColor=\"{DynamicResource PageBackgroundColor}\">\n    \u003CLabel Text=\"Hello\"\n           TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n    \u003CButton Text=\"Action\"\n            BackgroundColor=\"{DynamicResource AccentColor}\" \u002F>\n\u003C\u002FContentPage>\n```\n\n### Step 3 — Switch Themes at Runtime\n\n> 🚨 **Never call `MergedDictionaries.Clear()` to swap a theme.** The default MAUI\n> template merges `Resources\u002FStyles\u002FColors.xaml` and `Styles.xaml` into\n> `Application.Resources`. `Clear()` removes **those too**, so every implicit style,\n> brush and colour in the app silently disappears — buttons, entries and labels all\n> revert to unstyled defaults. Verified: after `Clear()`, `MergedDictionaries` drops\n> from 2 to 1 and the template's `Primary` colour no longer resolves.\n\nRemove only the theme you added, and leave everything else alone:\n\n```csharp\nstatic ResourceDictionary? _currentTheme;\n\nvoid ApplyTheme(ResourceDictionary theme)\n{\n    var merged = Application.Current!.Resources.MergedDictionaries;\n\n    \u002F\u002F ✅ Remove ONLY the previous theme — Colors.xaml \u002F Styles.xaml survive\n    if (_currentTheme is not null)\n        merged.Remove(_currentTheme);\n\n    merged.Add(theme);\n    _currentTheme = theme;\n}\n\n\u002F\u002F Usage\nApplyTheme(new DarkTheme());\n```\n\n```csharp\n\u002F\u002F ❌ Destroys the app's Colors.xaml and Styles.xaml along with the old theme\nvar merged = Application.Current!.Resources.MergedDictionaries;\nmerged.Clear();\nmerged.Add(theme);\n```\n\n## System Theme Detection\n\n### Read the Current Theme\n\n```csharp\nAppTheme currentTheme = Application.Current!.RequestedTheme;\n\u002F\u002F Returns AppTheme.Light, AppTheme.Dark, or AppTheme.Unspecified\n```\n\n### Override the System Theme\n\n```csharp\n\u002F\u002F Force dark mode regardless of OS setting\nApplication.Current!.UserAppTheme = AppTheme.Dark;\n\n\u002F\u002F Reset to follow system theme\nApplication.Current!.UserAppTheme = AppTheme.Unspecified;\n```\n\n### React to Theme Changes\n\n```csharp\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n{\n    AppTheme newTheme = e.RequestedTheme;\n    \u002F\u002F Update UI or switch ResourceDictionaries\n};\n```\n\n## Combining Both Approaches\n\nUse `AppThemeBinding` with `DynamicResource` values for maximum flexibility — the\nnested `DynamicResource` stays live, so swapping the dictionary updates the value\n*and* the OS light\u002Fdark switch is still honoured:\n\n```xml\n\u003CLabel TextColor=\"{AppThemeBinding\n    Light={DynamicResource LightPrimary},\n    Dark={DynamicResource DarkPrimary}}\" \u002F>\n```\n\nOr react to system changes and swap full dictionaries:\n\n```csharp\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n{\n    ApplyTheme(e.RequestedTheme == AppTheme.Dark\n        ? new DarkTheme()\n        : new LightTheme());\n};\n```\n\n## Saving and Restoring User Preference\n\nStore the user's choice with `Preferences` and apply it on startup:\n\n```csharp\n\u002F\u002F Save choice\nPreferences.Set(\"AppTheme\", \"Dark\");\n\n\u002F\u002F Restore on startup (in App constructor or CreateWindow)\nvar saved = Preferences.Get(\"AppTheme\", \"System\");\nApplication.Current!.UserAppTheme = saved switch\n{\n    \"Light\" => AppTheme.Light,\n    \"Dark\"  => AppTheme.Dark,\n    _       => AppTheme.Unspecified\n};\n```\n\n## Common Pitfalls\n\n### Android: ConfigChanges.UiMode is Required\n\n`MainActivity` **must** include `ConfigChanges.UiMode` or theme-change events will not fire and the activity restarts instead of handling the change gracefully:\n\n```csharp\n[Activity(Theme = \"@style\u002FMaui.SplashTheme\",\n          MainLauncher = true,\n          ConfigurationChanges = ConfigChanges.ScreenSize\n                               | ConfigChanges.Orientation\n                               | ConfigChanges.UiMode  \u002F\u002F ← Required for theme detection\n                               | ConfigChanges.ScreenLayout\n                               | ConfigChanges.SmallestScreenSize\n                               | ConfigChanges.Density)]\npublic class MainActivity : MauiAppCompatActivity { }\n```\n\nWithout `UiMode`, toggling dark mode in Android settings causes a full activity restart — losing navigation state and appearing as a crash. With it declared, the app stays alive and `RequestedThemeChanged` fires, so pair this fix with a handler that re-applies the theme (see below).\n\n### DynamicResource vs StaticResource\n\nWhen using ResourceDictionary theme switching, you **must** use `DynamicResource`:\n\n```xml\n\u003C!-- ✅ Updates when theme dictionary changes -->\n\u003CLabel TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n\n\u003C!-- ❌ Frozen at first load — won't update on theme switch -->\n\u003CLabel TextColor=\"{StaticResource PrimaryTextColor}\" \u002F>\n```\n\n`DynamicResource` only helps if something actually swaps the dictionary. When you\ndiagnose this, always show the swap and the system-theme hook alongside the fix —\notherwise the user has a corrected binding that still never updates:\n\n```csharp\nstatic ResourceDictionary? _currentTheme;\n\nvoid ApplyTheme(bool useDark)\n{\n    var merged = Application.Current!.Resources.MergedDictionaries;\n\n    \u002F\u002F Remove only the previous theme — never Clear(), which also wipes\n    \u002F\u002F the template's Colors.xaml \u002F Styles.xaml\n    if (_currentTheme is not null)\n        merged.Remove(_currentTheme);\n\n    _currentTheme = useDark ? new DarkTheme() : new LightTheme();\n    merged.Add(_currentTheme);\n}\n\n\u002F\u002F React to the OS switching light\u002Fdark\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n    ApplyTheme(e.RequestedTheme == AppTheme.Dark);\n```\n\n### Hardcoded Colors Break Theming\n\nAvoid inline color values on elements that should respect the theme:\n\n```xml\n\u003C!-- ❌ Will not change with theme -->\n\u003CLabel TextColor=\"#333333\" \u002F>\n\n\u003C!-- ✅ Theme-aware -->\n\u003CLabel TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n```\n\n### CSS Themes Cannot Be Swapped at Runtime\n\n.NET MAUI supports CSS styling, but CSS-based themes **cannot be swapped dynamically**. Use ResourceDictionary theming for runtime switching.\n\n### Theme Keys Must Match Across Dictionaries\n\nEvery `x:Key` used in one theme dictionary must exist in all other theme dictionaries. A missing key causes a silent fallback to the default value, leading to inconsistent appearance.\n\n## Platform Support\n\n| Platform       | Minimum Version |\n|----------------|-----------------|\n| iOS            | 13+             |\n| Android        | 10+ (API 29)    |\n| macOS Catalyst | 10.15+          |\n| Windows        | 10+             |\n\n## Quick Reference\n\n- **OS light\u002Fdark** → `AppThemeBinding` markup extension\n- **Theme colors in C#** → `SetAppThemeColor()`, `SetAppTheme\u003CT>()`\n- **Read OS theme** → `Application.Current.RequestedTheme`\n- **Force theme** → `Application.Current.UserAppTheme = AppTheme.Dark`\n- **Theme changes** → `RequestedThemeChanged` event\n- **Custom switching** → `Remove` the old theme from `MergedDictionaries`, then `Add` the new one — **never `Clear()`**\n- **Runtime bindings** → **`DynamicResource`** (not `StaticResource`)\n- **Persist choice** → `Preferences.Set` \u002F `Preferences.Get`\n","# .NET MAUI Theming\n\nApply light\u002Fdark mode support, custom branded themes, and runtime theme switching in .NET MAUI apps using AppThemeBinding, ResourceDictionary swapping, and system theme detection APIs.\n\n## When to Use\n\n- Adding light and dark mode support to a .NET MAUI app\n- Creating custom branded themes with ResourceDictionary\n- Detecting and responding to system theme changes at runtime\n- Letting users choose a preferred theme (light, dark, or system default)\n- Combining OS-driven theme response with custom color palettes\n\n## When Not to Use\n\n- Localization or language switching — see [.NET MAUI localization docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Flocalization)\n- Accessibility-specific visual adjustments — see [.NET MAUI accessibility docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Ffundamentals\u002Faccessibility)\n- App icon or splash screen configuration — see [.NET MAUI app icon docs](https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fmaui\u002Fuser-interface\u002Fimages\u002Fapp-icons)\n- Bootstrap-style class theming — see the `Plugin.Maui.BootstrapTheme` NuGet package\n\n## Inputs\n\n- A .NET MAUI project targeting .NET 8 or later\n- XAML pages or C# UI code that need theme-aware styling\n\n## Workflow\n\n1. Detect the current theme approach in the project (AppThemeBinding, ResourceDictionary, or none).\n2. Choose the appropriate strategy: AppThemeBinding for simple light\u002Fdark, ResourceDictionary swap for custom\u002Fmultiple themes, or both combined.\n3. Define theme resources — inline `AppThemeBinding` values or separate `ResourceDictionary` files with matching keys.\n4. Replace hardcoded colors with `DynamicResource` bindings (or `AppThemeBinding` markup) throughout XAML pages.\n5. Add system theme detection via `Application.Current.RequestedTheme` and the `RequestedThemeChanged` event.\n6. Implement user preference persistence with `Preferences.Set` \u002F `Preferences.Get` and apply on startup.\n7. Verify Android `ConfigChanges.UiMode` is set on `MainActivity` to avoid activity restarts on theme change.\n8. Test both light and dark themes on at least one target platform, confirming all UI elements respond correctly.\n\n## Rules That Change the Answer\n\nCheck these rules against the user's scenario, and apply **only** the ones that\naffect what they asked. `UiMode` and dictionary swapping matter for *runtime theme\nswitching*; they are noise in a question about setting up `AppThemeBinding`.\n\n**Answer narrowly, but completely.** Completeness means showing the code that\nimplements *what you recommended* — not adding adjacent topics. If you recommend\n`DynamicResource`, show the dictionary swap that makes it update. If the user asks\nfor light\u002Fdark colours in C#, show **both** `SetAppThemeColor` (colours) and the\ngeneric `SetAppTheme\u003CT>` (any bindable property type), and prefer resource keys over\nscattered hardcoded colours. Do not tack on platform configuration the question\ndidn't raise.\n\n| Rule | Do this | Not this | Why |\n|---|---|---|---|\n| **Runtime-swapped values must be dynamic** | `{DynamicResource Key}` | `{StaticResource Key}` | `StaticResource` resolves once at load and never updates when dictionaries are swapped. |\n| **Android must declare `UiMode`** *(only for runtime\u002Fsystem 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 |\n| **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. |\n\n**Do not** replace a working `AppThemeBinding` setup with ResourceDictionary\nswapping (or vice versa) unless the user needs what the other approach provides —\nmore than two themes, or a user-selectable theme.\n\n## Choosing an Approach\n\n| Approach | Best for | Limitation |\n|----------|----------|------------|\n| **AppThemeBinding** | Automatic light\u002Fdark with OS — minimal code | Only two themes (light + dark) |\n| **ResourceDictionary swap** | Custom branded themes, more than two themes, user preference | More setup; must use `DynamicResource` everywhere |\n| **Both combined** | OS-driven response plus custom theme colors | Most flexible but most complex |\n\n## AppThemeBinding (OS Light\u002FDark)\n\n`AppThemeBinding` selects a value based on the current system theme. It supports `Light`, `Dark`, and an optional `Default` fallback.\n\n### Define the palette once — don't scatter literals\n\nPutting `{AppThemeBinding Light=#333333, Dark=#FFFFFF}` on every element is the\nsingle most common theming mistake: the palette ends up duplicated across dozens of\nfiles and cannot be changed in one place. **Recommend this shape as the final\nanswer**, not inline literals:\n\n```xml\n\u003C!-- App.xaml — one source of truth for the whole app -->\n\u003CApplication.Resources>\n    \u003CResourceDictionary>\n\n        \u003C!-- 1. Raw palette -->\n        \u003CColor x:Key=\"LightPageBackground\">#FFFFFF\u003C\u002FColor>\n        \u003CColor x:Key=\"DarkPageBackground\">#1E1E1E\u003C\u002FColor>\n        \u003CColor x:Key=\"LightPrimaryText\">#333333\u003C\u002FColor>\n        \u003CColor x:Key=\"DarkPrimaryText\">#E0E0E0\u003C\u002FColor>\n\n        \u003C!-- 2. Implicit styles bind the pair once; every page inherits them -->\n        \u003CStyle TargetType=\"ContentPage\" ApplyToDerivedTypes=\"True\">\n            \u003CSetter Property=\"BackgroundColor\"\n                    Value=\"{AppThemeBinding Light={StaticResource LightPageBackground},\n                                            Dark={StaticResource DarkPageBackground}}\" \u002F>\n        \u003C\u002FStyle>\n\n        \u003CStyle TargetType=\"Label\">\n            \u003CSetter Property=\"TextColor\"\n                    Value=\"{AppThemeBinding Light={StaticResource LightPrimaryText},\n                                            Dark={StaticResource DarkPrimaryText}}\" \u002F>\n        \u003C\u002FStyle>\n\n    \u003C\u002FResourceDictionary>\n\u003C\u002FApplication.Resources>\n```\n\nPages then need **no theming markup at all** — they pick the styles up implicitly.\nUse an inline `AppThemeBinding` only for genuine one-offs, and even then reference\n`{StaticResource}` keys rather than literal hex.\n\n### XAML (inline form, for one-offs)\n\n```xml\n\u003CLabel Text=\"Themed text\"\n       TextColor=\"{AppThemeBinding Light=Green, Dark=Red}\"\n       BackgroundColor=\"{AppThemeBinding Light=White, Dark=Black}\" \u002F>\n\n\u003C!-- With resource references — preferred over literals -->\n\u003CLabel TextColor=\"{AppThemeBinding Light={StaticResource LightPrimary},\n                                   Dark={StaticResource DarkPrimary}}\" \u002F>\n```\n\n### C# Extension Methods\n\nShow **both** when answering a \"light\u002Fdark colours in C#\" question — `SetAppThemeColor`\ncovers `Color` properties, `SetAppTheme\u003CT>` covers everything else:\n\n```csharp\nvar label = new Label();\n\n\u002F\u002F Color-specific helper\nlabel.SetAppThemeColor(Label.TextColorProperty, Colors.Green, Colors.Red);\n\n\u002F\u002F Generic helper — works for any bindable property type, not just Color\nlabel.SetAppTheme\u003CColor>(Label.TextColorProperty, Colors.Green, Colors.Red);\nlabel.SetAppTheme\u003Cdouble>(Label.FontSizeProperty, 14, 16);\n\n\u002F\u002F The BindableProperty must belong to the object you call it on —\n\u002F\u002F Image.SourceProperty goes on an Image, not a Label.\nvar image = new Image();\nimage.SetAppTheme\u003CImageSource>(Image.SourceProperty,\n    ImageSource.FromFile(\"logo_light.png\"),\n    ImageSource.FromFile(\"logo_dark.png\"));\n```\n\nPrefer defining the values as resource keys and referencing them, rather than\nscattering hardcoded colours across the codebase.\n\n## ResourceDictionary Theming (Custom Themes)\n\nUse separate `ResourceDictionary` files with matching keys to define themes, then swap them at runtime.\n\n### Step 1 — Define Theme Dictionaries\n\nWhen using compiled XAML with `x:Class` (as shown below), each dictionary needs a code-behind that calls `InitializeComponent()`. Dictionaries loaded via `Source` without `x:Class` do not need code-behind.\n\n**LightTheme.xaml**\n\n```xml\n\u003CResourceDictionary xmlns=\"http:\u002F\u002Fschemas.microsoft.com\u002Fdotnet\u002F2021\u002Fmaui\"\n                    xmlns:x=\"http:\u002F\u002Fschemas.microsoft.com\u002Fwinfx\u002F2009\u002Fxaml\"\n                    x:Class=\"MyApp.Themes.LightTheme\">\n    \u003CColor x:Key=\"PageBackgroundColor\">White\u003C\u002FColor>\n    \u003CColor x:Key=\"PrimaryTextColor\">#333333\u003C\u002FColor>\n    \u003CColor x:Key=\"AccentColor\">#2196F3\u003C\u002FColor>\n\u003C\u002FResourceDictionary>\n```\n\n**LightTheme.xaml.cs**\n\n```csharp\nnamespace MyApp.Themes;\n\npublic partial class LightTheme : ResourceDictionary\n{\n    public LightTheme() => InitializeComponent();\n}\n```\n\nCreate a matching **DarkTheme.xaml \u002F DarkTheme.xaml.cs** with the same keys and different values.\n\n### Step 2 — Consume with DynamicResource\n\nUse `DynamicResource` so values update when the dictionary is swapped at runtime:\n\n```xml\n\u003CContentPage BackgroundColor=\"{DynamicResource PageBackgroundColor}\">\n    \u003CLabel Text=\"Hello\"\n           TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n    \u003CButton Text=\"Action\"\n            BackgroundColor=\"{DynamicResource AccentColor}\" \u002F>\n\u003C\u002FContentPage>\n```\n\n### Step 3 — Switch Themes at Runtime\n\n> 🚨 **Never call `MergedDictionaries.Clear()` to swap a theme.** The default MAUI\n> template merges `Resources\u002FStyles\u002FColors.xaml` and `Styles.xaml` into\n> `Application.Resources`. `Clear()` removes **those too**, so every implicit style,\n> brush and colour in the app silently disappears — buttons, entries and labels all\n> revert to unstyled defaults. Verified: after `Clear()`, `MergedDictionaries` drops\n> from 2 to 1 and the template's `Primary` colour no longer resolves.\n\nRemove only the theme you added, and leave everything else alone:\n\n```csharp\nstatic ResourceDictionary? _currentTheme;\n\nvoid ApplyTheme(ResourceDictionary theme)\n{\n    var merged = Application.Current!.Resources.MergedDictionaries;\n\n    \u002F\u002F ✅ Remove ONLY the previous theme — Colors.xaml \u002F Styles.xaml survive\n    if (_currentTheme is not null)\n        merged.Remove(_currentTheme);\n\n    merged.Add(theme);\n    _currentTheme = theme;\n}\n\n\u002F\u002F Usage\nApplyTheme(new DarkTheme());\n```\n\n```csharp\n\u002F\u002F ❌ Destroys the app's Colors.xaml and Styles.xaml along with the old theme\nvar merged = Application.Current!.Resources.MergedDictionaries;\nmerged.Clear();\nmerged.Add(theme);\n```\n\n## System Theme Detection\n\n### Read the Current Theme\n\n```csharp\nAppTheme currentTheme = Application.Current!.RequestedTheme;\n\u002F\u002F Returns AppTheme.Light, AppTheme.Dark, or AppTheme.Unspecified\n```\n\n### Override the System Theme\n\n```csharp\n\u002F\u002F Force dark mode regardless of OS setting\nApplication.Current!.UserAppTheme = AppTheme.Dark;\n\n\u002F\u002F Reset to follow system theme\nApplication.Current!.UserAppTheme = AppTheme.Unspecified;\n```\n\n### React to Theme Changes\n\n```csharp\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n{\n    AppTheme newTheme = e.RequestedTheme;\n    \u002F\u002F Update UI or switch ResourceDictionaries\n};\n```\n\n## Combining Both Approaches\n\nUse `AppThemeBinding` with `DynamicResource` values for maximum flexibility — the\nnested `DynamicResource` stays live, so swapping the dictionary updates the value\n*and* the OS light\u002Fdark switch is still honoured:\n\n```xml\n\u003CLabel TextColor=\"{AppThemeBinding\n    Light={DynamicResource LightPrimary},\n    Dark={DynamicResource DarkPrimary}}\" \u002F>\n```\n\nOr react to system changes and swap full dictionaries:\n\n```csharp\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n{\n    ApplyTheme(e.RequestedTheme == AppTheme.Dark\n        ? new DarkTheme()\n        : new LightTheme());\n};\n```\n\n## Saving and Restoring User Preference\n\nStore the user's choice with `Preferences` and apply it on startup:\n\n```csharp\n\u002F\u002F Save choice\nPreferences.Set(\"AppTheme\", \"Dark\");\n\n\u002F\u002F Restore on startup (in App constructor or CreateWindow)\nvar saved = Preferences.Get(\"AppTheme\", \"System\");\nApplication.Current!.UserAppTheme = saved switch\n{\n    \"Light\" => AppTheme.Light,\n    \"Dark\"  => AppTheme.Dark,\n    _       => AppTheme.Unspecified\n};\n```\n\n## Common Pitfalls\n\n### Android: ConfigChanges.UiMode is Required\n\n`MainActivity` **must** include `ConfigChanges.UiMode` or theme-change events will not fire and the activity restarts instead of handling the change gracefully:\n\n```csharp\n[Activity(Theme = \"@style\u002FMaui.SplashTheme\",\n          MainLauncher = true,\n          ConfigurationChanges = ConfigChanges.ScreenSize\n                               | ConfigChanges.Orientation\n                               | ConfigChanges.UiMode  \u002F\u002F ← Required for theme detection\n                               | ConfigChanges.ScreenLayout\n                               | ConfigChanges.SmallestScreenSize\n                               | ConfigChanges.Density)]\npublic class MainActivity : MauiAppCompatActivity { }\n```\n\nWithout `UiMode`, toggling dark mode in Android settings causes a full activity restart — losing navigation state and appearing as a crash. With it declared, the app stays alive and `RequestedThemeChanged` fires, so pair this fix with a handler that re-applies the theme (see below).\n\n### DynamicResource vs StaticResource\n\nWhen using ResourceDictionary theme switching, you **must** use `DynamicResource`:\n\n```xml\n\u003C!-- ✅ Updates when theme dictionary changes -->\n\u003CLabel TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n\n\u003C!-- ❌ Frozen at first load — won't update on theme switch -->\n\u003CLabel TextColor=\"{StaticResource PrimaryTextColor}\" \u002F>\n```\n\n`DynamicResource` only helps if something actually swaps the dictionary. When you\ndiagnose this, always show the swap and the system-theme hook alongside the fix —\notherwise the user has a corrected binding that still never updates:\n\n```csharp\nstatic ResourceDictionary? _currentTheme;\n\nvoid ApplyTheme(bool useDark)\n{\n    var merged = Application.Current!.Resources.MergedDictionaries;\n\n    \u002F\u002F Remove only the previous theme — never Clear(), which also wipes\n    \u002F\u002F the template's Colors.xaml \u002F Styles.xaml\n    if (_currentTheme is not null)\n        merged.Remove(_currentTheme);\n\n    _currentTheme = useDark ? new DarkTheme() : new LightTheme();\n    merged.Add(_currentTheme);\n}\n\n\u002F\u002F React to the OS switching light\u002Fdark\nApplication.Current!.RequestedThemeChanged += (s, e) =>\n    ApplyTheme(e.RequestedTheme == AppTheme.Dark);\n```\n\n### Hardcoded Colors Break Theming\n\nAvoid inline color values on elements that should respect the theme:\n\n```xml\n\u003C!-- ❌ Will not change with theme -->\n\u003CLabel TextColor=\"#333333\" \u002F>\n\n\u003C!-- ✅ Theme-aware -->\n\u003CLabel TextColor=\"{DynamicResource PrimaryTextColor}\" \u002F>\n```\n\n### CSS Themes Cannot Be Swapped at Runtime\n\n.NET MAUI supports CSS styling, but CSS-based themes **cannot be swapped dynamically**. Use ResourceDictionary theming for runtime switching.\n\n### Theme Keys Must Match Across Dictionaries\n\nEvery `x:Key` used in one theme dictionary must exist in all other theme dictionaries. A missing key causes a silent fallback to the default value, leading to inconsistent appearance.\n\n## Platform Support\n\n| Platform       | Minimum Version |\n|----------------|-----------------|\n| iOS            | 13+             |\n| Android        | 10+ (API 29)    |\n| macOS Catalyst | 10.15+          |\n| Windows        | 10+             |\n\n## Quick Reference\n\n- **OS light\u002Fdark** → `AppThemeBinding` markup extension\n- **Theme colors in C#** → `SetAppThemeColor()`, `SetAppTheme\u003CT>()`\n- **Read OS theme** → `Application.Current.RequestedTheme`\n- **Force theme** → `Application.Current.UserAppTheme = AppTheme.Dark`\n- **Theme changes** → `RequestedThemeChanged` event\n- **Custom switching** → `Remove` the old theme from `MergedDictionaries`, then `Add` the new one — **never `Clear()`**\n- **Runtime bindings** → **`DynamicResource`** (not `StaticResource`)\n- **Persist choice** → `Preferences.Set` \u002F `Preferences.Get`\n",{"name":5,"license":15,"description":7},"main","30954af1dcd1a74b63f05deb2e2c41e5ecae4a82","10-Mobile-Development\u002Fmaui-theming","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack","https:\u002F\u002Fgithub.com\u002Fitsmejay18","2026-09-18 16:06:36",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add itsmejay18\u002FAI-Skills-for-My-Development-Stack --skill maui-theming",{"tool":36,"command":37},"bunx","bunx skills add itsmejay18\u002FAI-Skills-for-My-Development-Stack --skill maui-theming",{"tool":39,"command":40},"pnpm","pnpm dlx skills add itsmejay18\u002FAI-Skills-for-My-Development-Stack --skill maui-theming","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F10-Mobile-Development\u002Fmaui-theming\u002FSKILL.md",true,[44],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"references\u002Ftheming-api.md","REFERENCE","参考文档",4344,"https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F10-Mobile-Development\u002Fmaui-theming\u002Freferences\u002Ftheming-api.md",[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":19},"01M7D2RKBHPZ3E1RNN5DWHT550","vectorization","Design, implement, optimize, and review SIMD code in .NET. USE FOR: vectorizing scalar loops with TensorPrimitives, Vector64\u002F128\u002F256\u002F512, or platform hardware intrinsics; reviewing existing SIMD code, including Vector\u003CT>, for contract equivalence, tail handling, memory safety, portability, fallbacks, and measured performance. DO NOT USE FOR: performance work unrelated to SIMD or vectorization.","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Fvectorization\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7D2RDJ7RN3QK8GJR0QTER1D","resolve-project-references","Guide for interpreting ResolveProjectReferences time in MSBuild performance summaries. Activate when ResolveProjectReferences appears as the most expensive target and developers are trying to optimize it directly. Explains that the reported time includes wait time for dependent project builds and is misleading. Guides users to focus on task self-time instead. Do not activate for general build performance -- use build-perf-diagnostics instead.","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Fresolve-project-references\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7D2R1H2GTNZYHG9YRX3JDQW","optimizing-ef-core-queries","Optimize and improve the performance of slow Entity Framework Core (EF Core) queries: make them generate less SQL, make fewer database round-trips, and return results faster. Use whenever an EF Core or DbContext query or data-access path is slow or should be made faster — whether or not EF Core owns the database schema. For EF Core, not Dapper or raw ADO.NET.","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Foptimizing-ef-core-queries\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M7D2QREG04W1YT0NEBHEW5C9","microbenchmarking","Activate this skill when BenchmarkDotNet (BDN) is involved in the task — creating, running, configuring, or reviewing BDN benchmarks. Also activate when microbenchmarking .NET code would be useful and BenchmarkDotNet is the likely tool. Consider activating when answering a .NET performance question requires measurement and BenchmarkDotNet may be needed. Covers microbenchmark design, BDN configuration and project setup, how to run BDN microbenchmarks efficiently and effectively, and using BDN for side-by-side performance comparisons. Do NOT use for profiling\u002Ftracing .NET code (dotnet-trace, PerfView), production telemetry, or load\u002Fstress testing (Crank, k6).","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Fmicrobenchmarking\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7D2QGE175XWPZVACVH2868Z","incremental-build","Guide for optimizing MSBuild incremental builds. USE FOR: builds slower than expected on subsequent runs, 'nothing changed but it rebuilds anyway', diagnosing why targets re-execute unnecessarily, fixing broken no-op builds. Covers 8 common causes: missing Inputs\u002FOutputs on custom targets, volatile properties in output paths (timestamps\u002FGUIDs), file writes outside tracked Outputs, missing FileWrites registration, glob changes, Visual Studio Fast Up-to-Date Check (FUTDC) issues. Key diagnostic: look for 'Building target completely' vs 'Skipping target' in binlog. DO NOT USE FOR: first-time build slowness (use build-perf-baseline), parallelism issues (use build-parallelism), evaluation-phase slowness (use eval-performance), non-MSBuild build systems.","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Fincremental-build\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M7D2Q1DQTC6K49R73WQTTPSB","eval-performance","Guide for diagnosing and improving MSBuild project evaluation performance. USE FOR: builds slow before any compilation starts, high evaluation time in binlog analysis, expensive glob patterns walking large directories (node_modules, .git, bin\u002Fobj), deep import chains (>20 levels), preprocessed output >10K lines indicating heavy evaluation, property functions with file I\u002FO ($([System.IO.File]::ReadAllText(...))), multiple evaluations per project. Covers the 5 MSBuild evaluation phases, glob optimization via DefaultItemExcludes, import chain analysis with \u002Fpp preprocessing. DO NOT USE FOR: compilation-time slowness (use build-perf-diagnostics), incremental build issues (use incremental-build), non-MSBuild build systems.","https:\u002F\u002Fgithub.com\u002Fitsmejay18\u002FAI-Skills-for-My-Development-Stack\u002Fblob\u002Fmain\u002F20-Performance-Optimization\u002Feval-performance\u002FSKILL.md",[],[]]