maui-theming
Skill này làm gì
Skill này hướng dẫn theme trong ứng dụng .NET MAUI, gồm chế độ sáng và tối cùng theme màu tùy chỉnh. Skill dành cho lập trình viên muốn ứng dụng theo theme của hệ thống hoặc để người dùng tự chọn.
Khi nào nên dùng
- ✓Khi bạn muốn ứng dụng .NET MAUI hỗ trợ chế độ sáng và tối.
- ✓Khi bạn muốn chuyển theme khi đang chạy hoặc để người dùng chọn một theme.
- ✓Khi bạn muốn thiết lập một theme màu có thương hiệu bằng resource dictionary.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-theming/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thêm chế độ tối vào ứng dụng MAUI của tôi và cho người dùng chọn sáng, tối hoặc theo hệ thống trong phần cài đặt.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent dùng theme binding cho màu sáng và tối đơn giản, hoặc hoán đổi resource dictionary cho theme tùy chỉnh, và phản hồi theo theme của hệ thống cũng như lựa chọn của người dùng.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
.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
- Localization or language switching — see .NET MAUI localization docs
- Accessibility-specific visual adjustments — see .NET MAUI accessibility docs
- App icon or splash screen configuration — see .NET MAUI app icon docs
- Bootstrap-style class theming — see the
Plugin.Maui.BootstrapThemeNuGet package
Inputs
- A .NET MAUI project targeting .NET 8 or later
- XAML pages or C# UI code that need theme-aware styling
Workflow
- Detect the current theme approach in the project (AppThemeBinding, ResourceDictionary, or none).
- Choose the appropriate strategy: AppThemeBinding for simple light/dark, ResourceDictionary swap for custom/multiple themes, or both combined.
- Define theme resources — inline
AppThemeBindingvalues or separateResourceDictionaryfiles with matching keys. - Replace hardcoded colors with
DynamicResourcebindings (orAppThemeBindingmarkup) throughout XAML pages. - Add system theme detection via
Application.Current.RequestedThemeand theRequestedThemeChangedevent. - Implement user preference persistence with
Preferences.Set/Preferences.Getand apply on startup. - Verify Android
ConfigChanges.UiModeis set onMainActivityto avoid activity restarts on theme change. - 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,
Câu hỏi thường gặp
Skill có theo theme của hệ thống không?
Có. Skill bao quát việc phản hồi theme hệ thống và lựa chọn của người dùng.
Skill có bao quát bản địa hóa không?
Không. Việc chuyển đổi ngôn ngữ do hướng dẫn riêng đảm nhiệm.
Skill có bao quát icon ứng dụng không?
Không. Icon ứng dụng và màn hình chờ nằm ngoài phạm vi.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14589
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-custom-agent
5.8kGiúp agent của bạn tạo file custom agent cho VS Code, với các tool, hướng dẫn và handoff riêng sang agent khác.
create-skill
5.8kGiúp agent của bạn tạo một agent skill mới với tên hợp lệ, mô tả kích hoạt rõ ràng và file SKILL.md đúng tiêu chuẩn.
csharp-scripts
5.8kGiúp agent của bạn chạy một chương trình C# nhỏ dưới dạng một file duy nhất bằng công cụ dòng lệnh .NET, không cần tạo project đầy đủ.
dotnet-pinvoke
5.8kGiúp agent của bạn gọi các thư viện native C hoặc C++ từ .NET đúng cách, gồm khai báo chữ ký, xử lý chuỗi, bộ nhớ và safe handle.
Skill tương tự
android-clean-architecture
280kGiúp agent của bạn tổ chức dự án Android hiệu quả, cấu trúc code để việc bảo trì và phát triển tính năng mới dễ dàng hơn.
compose-multiplatform-patterns
280kGiúp agent của bạn dùng các mẫu Compose Multiplatform và Jetpack Compose trong dự án KMP, gồm trạng thái, điều hướng, giao diện và hiệu năng.
dart-flutter-patterns
280kGiúp agent của bạn viết code cho ứng dụng Dart và Flutter. Agent dùng các mẫu hiện đại để tạo ứng dụng vững chắc và dễ quản lý.