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

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

TestProject.zip
다운로드

▶ 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"
    Width="800"
    Height="600"
    Title="ControlTemplate 엘리먼트 : CheckBox 엘리먼트 정의하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <ControlTemplate x:Key="CheckBoxTemplateKey" TargetType="{x:Type CheckBox}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border
                    Width="100"
                    Height="70"
                    BorderBrush="Black"
                    BorderThickness="1">
                    <Canvas Background="LightGray">
                        <TextBlock
                            Canvas.Left="0"
                            Canvas.Top="0"
                            Margin="2"
                            Foreground="Black"
                            Text="OFF" />
                        <TextBlock
                            Canvas.Right="0"
                            Canvas.Top="0"
                            Margin="2"
                            Foreground="Black"
                            Text="ON" />
                        <Line Name="offLine"
                            Stroke="Black"
                            StrokeThickness="8"
                            StrokeStartLineCap="Round"
                            StrokeEndLineCap="Round"
                            X1="50"
                            Y1="60"
                            X2="25"
                            Y2="30" />
                        <Line Name="onLine"
                            Stroke="Black"
                            StrokeThickness="8"
                            StrokeStartLineCap="Round"
                            StrokeEndLineCap="Round"
                            X1="50"
                            Y1="60"
                            X2="75"
                            Y2="30"
                            Visibility="Hidden" />
                    </Canvas>
                </Border>
                <ContentPresenter Grid.Row="1"
                    HorizontalAlignment="Center"
                    Margin="5"
                    Content="{TemplateBinding Content}" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter TargetName="offLine" Property="Visibility" Value="Hidden"  />
                    <Setter TargetName="onLine"  Property="Visibility" Value="Visible" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <CheckBox
        Template="{StaticResource CheckBoxTemplateKey}"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Content="마스터 스위치" />
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요