← ClaudeAtlas

customizing-controltemplatelisted

Customizes WPF control appearance using ControlTemplate with TemplateBinding and ContentPresenter. Use when completely changing control visuals, implementing state-based feedback, or TemplatedParent binding.
christian289/dotnet-with-claudecode · ★ 41 · Data & Documents · score 73
Install: claude install-skill christian289/dotnet-with-claudecode
# WPF ControlTemplate Patterns All controls inherited from the Control class can completely redefine their visual structure through ControlTemplate. ## 1. Core Concepts ### ControlTemplate vs Style | Aspect | Style | ControlTemplate | |--------|-------|-----------------| | **Role** | Batch property value setting | Visual structure redefinition | | **Scope** | Property changes only | Full appearance change possible | | **Target** | All FrameworkElements | Control-derived classes only | ### ControlTemplate Components - **TargetType**: Control type to which the template applies - **TemplateBinding**: Connection to TemplatedParent properties - **ContentPresenter**: Specifies where Content property is rendered - **Triggers**: State-based visual changes --- ## 2. Basic Implementation Patterns ### 2.1 Button ControlTemplate (XAML) ```xml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type Button}" x:Key="RoundedButtonStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <!-- Visual structure definition --> <Border x:Name="PART_Border" CornerRadius="10" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding