■ ControlTemplate 엘리먼트를 사용해 GroupBox 엘리먼트를 정의하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
<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="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Color x:Key="ContentAreaLightColorKey">#ffc5cbf9</Color> <Color x:Key="ContentAreaDarkColorKey">#ff7381f9</Color> <Color x:Key="ControlLightColorKey">White</Color> <Color x:Key="ControlMediumColorKey">#ff7381f9</Color> <Color x:Key="BorderLightColorKey">#ffcccccc</Color> <Color x:Key="BorderMediumColorKey">#ff888888</Color> <Color x:Key="BorderDarkColorKey">#ff444444</Color> <Style TargetType="GroupBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="GroupBox"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Border Grid.Row="0" CornerRadius="2 2 0 0" BorderThickness="1"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0.0" Color="{DynamicResource BorderLightColorKey}" /> <GradientStop Offset="1.0" Color="{DynamicResource BorderDarkColorKey }" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush StartPoint="0 0" EndPoint="0 1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0.0" Color="{DynamicResource ControlLightColorKey }" /> <GradientStop Offset="1.0" Color="{DynamicResource ControlMediumColorKey}" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Border.Background> <ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" /> </Border> <Border Grid.Row="1" CornerRadius="0 0 2 2" BorderThickness="1 0 1 1"> <Border.BorderBrush> <SolidColorBrush Color="{StaticResource BorderMediumColorKey}" /> </Border.BorderBrush> <Border.Background> <LinearGradientBrush StartPoint="0.5 0" EndPoint="0.5 1" MappingMode="RelativeToBoundingBox"> <GradientStop Offset="0" Color="{DynamicResource ContentAreaLightColorKey}" /> <GradientStop Offset="1" Color="{DynamicResource ContentAreaDarkColorKey }" /> </LinearGradientBrush> </Border.Background> <ContentPresenter Margin="4" /> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <GroupBox HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="300" Header="테스트"> <Ellipse Fill="Yellow" /> </GroupBox> </Window> |