wpf-ui-shell
Create or refactor a .NET 8 WPF shell for a desktop widget host using CommunityToolkit.Mvvm and a custom viewmodel-first navigation service. Use when working on App.xaml, MainWindow/ShellWindow, shared ResourceDictionaries, runtime Light/Dark theming, or shell layout for widget-style apps. Avoid Prism, Frame navigation, and heavy region managers.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Wpf Ui Shell
Overview
Define the primary shell window, shared resources, and navigation contract for a WPF widget host app.
Constraints
- Target .NET 8
- CommunityToolkit.Mvvm
- ViewModel-first navigation via a custom service
- No Prism, no Frame navigation, no heavy region manager
- Fluent-inspired design system using native WPF styles
- Light/Dark themes via ResourceDictionaries with runtime switching
- Single shell window as primary host; secondary windows for widgets/tools/dialogs
Definition of done (DoD)
- Shell uses ContentControl host (not Frame) for navigation
- Navigation service updates CurrentViewModel, views resolve via DataTemplate
- Theme switching works at runtime without restart
- Secondary windows inherit shared resources
- Tray icon provides app access when shell is hidden
Workflow
- Locate shell files:
App.xaml, shell window XAML/code-behind, and theme dictionaries. - Confirm the shell layout uses a
ContentControlhost (notFrame). - Define or update the navigation service and VM-to-view mapping.
- Centralize shared styles in merged dictionaries and keep view XAML lean.
- Add runtime theme switching by swapping merged dictionaries.
- Ensure secondary windows inherit the same resources and chrome rules.
Shell layout pattern
Use a minimal, durable layout with explicit regions and a content host:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<!-- Title bar / nav -->
</DockPanel>
<ContentControl Grid.Row="1"
Content="{Binding CurrentViewModel}" />
</Grid>
ViewModel-first navigation
Map view models to views using DataTemplates in App.xaml (or a merged dictionary). The
navigation service updates CurrentViewModel on the shell VM.
<DataTemplate DataType="{x:Type vm:HomeViewModel}">
<views:HomeView />
</DataTemplate>
Resource dictionaries and themes
- Keep colors, brushes, typography, and control styles in merged dictionaries.
- Split themes into
Themes/Light.xamlandThemes/Dark.xaml. - Switch themes by replacing the theme dictionary at runtime.
References
-
references/shell-layouts.mdfor layout variants (title bar, nav, content host). -
references/navigation-service.mdfor VM-first navigation patterns. -
references/theme-switching.mdfor dictionary swap details. -
references/design-system.mdfor Fluent-inspired style guidance.
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!