■ ControlTemplate 엘리먼트를 사용해 Window 엘리먼트를 정의하는 방법을 보여준다.
▶ MainApplication.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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
<Application x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <Color x:Key="WindowColorKey">#ffe8edf9</Color> <Color x:Key="DisabledForegroundColorKey">#ff888888</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 x:Key="{x:Type StatusBar}" TargetType="{x:Type StatusBar}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type StatusBar}"> <Border Padding="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> <ItemsPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Static StatusBar.SeparatorStyleKey}" TargetType="{x:Type Separator}"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Separator}"> <Rectangle Margin="3" Width="1"> <Rectangle.Fill> <SolidColorBrush Color="{DynamicResource BorderMediumColorKey}" /> </Rectangle.Fill> </Rectangle> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type StatusBarItem}" TargetType="{x:Type StatusBarItem}"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type StatusBarItem}"> <ContentPresenter Margin="3" /> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground"> <Setter.Value> <SolidColorBrush Color="{StaticResource DisabledForegroundColorKey}" /> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type ResizeGrip}" TargetType="{x:Type ResizeGrip}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ResizeGrip}"> <Border Width="16" Height="16" Background="Transparent" SnapsToDevicePixels="True"> <Rectangle Margin="2"> <Rectangle.Fill> <DrawingBrush ViewportUnits="Absolute" Viewport="0 0 4 4" ViewboxUnits="Absolute" Viewbox="0 0 8 8" TileMode="Tile"> <DrawingBrush.Drawing> <DrawingGroup> <DrawingGroup.Children> <GeometryDrawing Brush="#ffe8edf9" Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z" /> </DrawingGroup.Children> </DrawingGroup> </DrawingBrush.Drawing> </DrawingBrush> </Rectangle.Fill> </Rectangle> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type Window}" TargetType="{x:Type Window}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <Grid> <Grid.Background> <SolidColorBrush Color="{DynamicResource WindowColorKey}" /> </Grid.Background> <AdornerDecorator> <ContentPresenter /> </AdornerDecorator> <ResizeGrip Name="windowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" IsTabStop="false" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="ResizeMode" Value="CanResizeWithGrip"> <Setter TargetName="windowResizeGrip" Property="Visibility" Value="Visible" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Application.Resources> </Application> |
▶ 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Style="{StaticResource {x:Type Window}}" Width="800" Height="600" Title="TestProject" ResizeMode="CanResizeWithGrip" FontFamily="나눔고딕코딩" FontSize="16"> <DockPanel LastChildFill="False"> <DockPanel.Background> <SolidColorBrush Color="{DynamicResource WindowColorKey}" /> </DockPanel.Background> <StatusBar DockPanel.Dock="Bottom"> <StatusBarItem> Ready </StatusBarItem> </StatusBar> </DockPanel> </Window> |