[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75MME5XJWMDYKY09XTFHT66":3,"skill-same:01M75MME5XJWMDYKY09XTFHT66":52},{"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":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M75MME5XJWMDYKY09XTFHT66","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).","stanfish06\u002Fskillquarium","stanfish06","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F93099613?v=4","01M75F1CK4ZW109ZK3T26VN52F","Zhiyuan","01M75F1CM53VH6F79DZ8GXKKES",12,"MIT","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fmaui-theming\u002FSKILL.md",[],[],"2026-11-12 13:55:43",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},"master","49e49abf2f670d429e0b7e2c0349739c3fdd5cbe","skills\u002Fmaui-theming",5,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium","https:\u002F\u002Fgithub.com\u002Fstanfish06","https:\u002F\u002Fwww.stanfish.dev\u002F","2026-11-14 21:31:37",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add stanfish06\u002Fskillquarium --skill maui-theming",{"tool":38,"command":39},"bunx","bunx skills add stanfish06\u002Fskillquarium --skill maui-theming",{"tool":41,"command":42},"pnpm","pnpm dlx skills add stanfish06\u002Fskillquarium --skill maui-theming","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fmaui-theming\u002FSKILL.md",true,[46],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Ftheming-api.md","REFERENCE","参考文档",4344,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fmaui-theming\u002Freferences\u002Ftheming-api.md",[53,60,69,76,83,90],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M76ZJTRVA456GD7K8Y3EP82H","zarr-python","Stores and queries chunked N-D scientific arrays with Zarr-Python 3, including codecs, sharding, S3\u002FGCS storage, and NumPy\u002FDask\u002FXarray integration. Use for array layout, bounded I\u002FO, format migration, or scientific metadata preservation.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":65,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M76ZJQZ15Q1HKC5V85NHE325","yeet","Publish local changes to GitHub by confirming scope, committing intentionally, pushing the branch, and opening a draft PR through the GitHub app from this plugin, with `gh` used only as a fallback where connector coverage is insufficient.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M76ZJ8ASZ4QYQ70Y6SBA4Z4S","xarray","N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF\u002FGRIB\u002FZarr files, climate\u002Fweather\u002Foceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fxarray\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M76ZHFBXD6VXPQ02VCEG202B","writing-mstest-tests","Use when asked to fix, rewrite, update, improve, modernize, show corrected code for, or explain existing MSTest tests or MSTest-specific configuration. Use for \"review\" when corrected code or edits are wanted, even for one pasted assertion or passing tests with bad failure output. Covers expected\u002Factual labels; generic Boolean, collection, string, numeric, null, identity, exception, hard-cast, and object[] checks; TestContext\u002Flifecycle; timeout\u002Fcancellation; OS\u002FCI conditions, retry, cleanup, parallelization, MSTest.Sdk project setup, and MSTESTxxxx. Honor the installed MSTest version. DO NOT USE to design new test cases (code-testing), perform report-only audits, create project files rather than explain MSTest setup, run tests, migrate frameworks, or handle non-MSTest\u002Fnon-.NET code.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwriting-mstest-tests\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M76ZDFDF4N88RH6HSYGS7GP2","wgs-prs","End-to-end WGS to polygenic risk score pipeline. Takes paired-end FASTQ files (or a pre-existing VCF) through nf-core\u002Fsarek for variant calling, applies VCF QC (normalisation, hard filtering, Ti\u002FTv and Het\u002FHom checks), then computes polygenic risk scores via the PGS Catalog. Fills the FASTQ to VCF gap upstream of the gwas-prs skill.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwgs-prs\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":94,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":19},"01M76ZCC1SC68J42QK4MDC8RCG","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[]]