<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="ControlTemplate 엘리먼트 : GroupBox 엘리먼트 정의하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<BorderGapMaskConverter x:Key="BorderGapMaskConverterKey" />
<Style TargetType="{x:Type GroupBox}">
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="4" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="4" />
</Grid.RowDefinitions>
<Border Grid.Row="1" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="4"
CornerRadius="4"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="Transparent"
Background="{TemplateBinding Background}" />
<Border Name="headerBorder" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"
Padding="6 0 6 0">
<ContentPresenter
ContentSource="Header"
RecognizesAccessKey="True" />
</Border>
<ContentPresenter Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"
Margin="{TemplateBinding Padding}" />
<Border Grid.Row="1" Grid.RowSpan="3" Grid.ColumnSpan="4"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="0">
<Border.OpacityMask>
<MultiBinding Converter="{StaticResource BorderGapMaskConverterKey}" ConverterParameter="6">
<Binding ElementName="headerBorder" Path="ActualWidth" />
<Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth" />
<Binding RelativeSource="{RelativeSource Self}" Path="ActualHeight" />
</MultiBinding>
</Border.OpacityMask>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<GroupBox
Margin="10"
Foreground="Black"
Header="그룹박스 헤더">
<Ellipse
Margin="30"
Fill="Orange" />
</GroupBox>
</Grid>
</Window>