728x90
반응형
728x170
■ ControlTemplate 엘리먼트를 사용해 Window 엘리먼트를 정의하는 방법을 보여준다.
▶ MainApplication.xaml
<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
<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>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] DataTemplateSelector 엘리먼트 : 데이터 객체 속성에 따라 DataTemplate 객체 선택하기 (0) | 2023.02.16 |
---|---|
[C#/WPF] 데이터 바인딩 사용하기 (0) | 2023.02.16 |
[C#/WPF] IValueConverter 인터페이스 : 날짜/시간↔문자열 변환자 사용하기 (0) | 2023.02.12 |
[C#/WPF] ValidationRule 클래스 : 현재 날짜보다 미래 날짜 여부 검증하기 (0) | 2023.02.12 |
[C#/WPF] IMultiValueConverter 인터페이스 사용하기 (0) | 2023.02.12 |
[C#/WPF] ControlTemplate 엘리먼트 : TreeView 엘리먼트 정의하기 (0) | 2023.02.10 |
[C#/WPF] ControlTemplate 엘리먼트 : ToolTip 엘리먼트 정의하기 (0) | 2023.02.10 |
[C#/WPF] ControlTemplate 엘리먼트 : ToolBar 엘리먼트 정의하기 (0) | 2023.02.09 |
[C#/WPF] ControlTemplate 엘리먼트 : Thumb 엘리먼트 정의하기 (0) | 2023.02.08 |
[C#/WPF] ControlTemplate 엘리먼트 : TextBox 엘리먼트 정의하기 (0) | 2023.02.07 |
댓글을 달아 주세요