Designs stand-alone control styles using WPF CustomControl and ResourceDictionary. Use when creating reusable custom controls or organizing control themes in Generic.xaml.
View on GitHubchristian289/dotnet-with-claudecode
wpf-dev-pack
wpf-dev-pack/skills/designing-wpf-customcontrol-architecture/SKILL.md
January 23, 2026
Select agents to install to:
npx add-skill https://github.com/christian289/dotnet-with-claudecode/blob/main/wpf-dev-pack/skills/designing-wpf-customcontrol-architecture/SKILL.md -a claude-code --skill designing-wpf-customcontrol-architectureInstallation paths:
.claude/skills/designing-wpf-customcontrol-architecture/# XAML Code Writing - WPF CustomControl
A guide for using CustomControl and ResourceDictionary when writing XAML code in WPF.
## Project Structure
The templates folder contains a .NET 9 WPF project example.
```
templates/
├── WpfCustomControlSample.Controls/ ← WPF Custom Control Library
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Themes/
│ │ ├── Generic.xaml ← MergedDictionaries hub
│ │ └── CustomButton.xaml ← Individual control style
│ ├── CustomButton.cs
│ ├── GlobalUsings.cs
│ └── WpfCustomControlSample.Controls.csproj
└── WpfCustomControlSample.App/ ← WPF Application
├── Views/
│ ├── MainWindow.xaml
│ └── MainWindow.xaml.cs
├── App.xaml
├── App.xaml.cs
├── GlobalUsings.cs
└── WpfCustomControlSample.App.csproj
```
## Basic Principles
**When generating XAML code, use CustomControl with Stand-Alone Control Style Resource through ResourceDictionary**
**Purpose**: Fix the timing of StaticResource loading and minimize style dependencies
## WPF Custom Control Library Project Structure
### Default Structure When Creating Project
```
YourProject/
├── Dependencies/
├── Themes/
│ └── Generic.xaml
├── AssemblyInfo.cs
└── CustomControl1.cs
```
### Restructure to Recommended Project Structure
```
YourProject/
├── Dependencies/
├── Properties/
│ └── AssemblyInfo.cs ← Moved
├── Themes/
│ ├── Generic.xaml ← Use as MergedDictionaries hub
│ ├── CustomButton.xaml ← Individual control style
│ └── CustomTextBox.xaml ← Individual control style
├── CustomButton.cs
└── CustomTextBox.cs
```
## Step-by-Step Setup
### 1. Create Properties Folder and Move AssemblyInfo.cs
- Create Properties folder in the project
- Move AssemblyInfo.cs to the Properties folder
### 2. Configure Generic.xaml - Use as MergedDictionaries Hub
Generic.xaml does not define styles directly; it only performs the role of merging individual ResourceDi