첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ ControlTemplate 엘리먼트를 사용해 Window 엘리먼트를 정의하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요