Explains WPF content model hierarchy including ContentControl, ItemsControl, and Headered variants. Use when selecting base classes for custom controls or understanding content/items properties.
View on GitHubchristian289/dotnet-with-claudecode
wpf-dev-pack
wpf-dev-pack/skills/understanding-wpf-content-model/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/understanding-wpf-content-model/SKILL.md -a claude-code --skill understanding-wpf-content-modelInstallation paths:
.claude/skills/understanding-wpf-content-model/# WPF Content Model Patterns
WPF controls are classified into 4 main models based on how they contain content.
## 1. Content Model Hierarchy
```
Control
├── ContentControl (Single Content)
│ ├── Button
│ ├── Label
│ ├── CheckBox
│ ├── RadioButton
│ ├── ToolTip
│ ├── ScrollViewer
│ ├── UserControl
│ ├── Window
│ └── HeaderedContentControl (Content + Header)
│ ├── Expander
│ ├── GroupBox
│ └── TabItem
│
└── ItemsControl (Multiple Items)
├── ListBox
├── ComboBox
├── ListView
├── TreeView
├── Menu
├── TabControl
└── HeaderedItemsControl (Items + Header)
├── MenuItem
├── TreeViewItem
└── ToolBar
```
---
## 2. ContentControl
### 2.1 Characteristics
- **Single Content property**: Holds only one child element
- **Content type**: object (allows all types)
- **ContentTemplate**: Specifies how Content is rendered
### 2.2 Basic Usage
```xml
<!-- String content -->
<Button Content="Click Me"/>
<!-- Complex content -->
<Button>
<StackPanel Orientation="Horizontal">
<Image Source="/icon.png" Width="16"/>
<TextBlock Text="Save" Margin="5,0,0,0"/>
</StackPanel>
</Button>
```
### 2.3 Using ContentTemplate
```xml
<Button Content="Download">
<Button.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Path Data="M12,2L12,14L8,10L12,14L16,10L12,14"
Fill="White" Width="16"/>
<TextBlock Text="{Binding}" Margin="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</Button.ContentTemplate>
</Button>
```
### 2.4 Creating ContentControl-Derived Controls
```csharp
namespace MyApp.Controls;
using System.Windows;
using System.Windows.Controls;
/// <summary>
/// Card control that displays single content
/// </summary>
public sealed class CardControl : ContentControl
{
static CardControl()
{
DefaultStyleKeyProperty.OverrideMe