첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

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 엘리먼트 : 리소스 형태로 Button 엘리먼트 정의하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <ControlTemplate x:Key="ButtonControlTemplateKey" TargetType="{x:Type Button}">
            <Border Name="border"
                BorderThickness="3"
                BorderBrush="Red"
                Background="{TemplateBinding Foreground}">
                <TextBlock Name="textBlock"
                    Margin="{TemplateBinding Padding}"
                    Foreground="{TemplateBinding Background}"
                    FontStyle="Italic"
                    Text="{TemplateBinding Content}" />
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="border"    Property="CornerRadius" Value="12"   />
                    <Setter TargetName="textBlock" Property="FontWeight"   Value="Bold" />
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="border"    Property="Background" Value="{Binding Path=Background}" />
                    <Setter TargetName="textBlock" Property="Foreground" Value="{Binding Path=Foreground}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Button
                Template="{StaticResource ButtonControlTemplateKey}"
                HorizontalAlignment="Center"
                Margin="24"
                Padding="10"
                FontSize="24">
                커스텀 템플리트 버튼
            </Button>
            <Button
                HorizontalAlignment="Center"
                Margin="24"
                Padding="10"
                FontSize="24">
                일반 버튼
            </Button>
            <Button
                Template="{StaticResource ButtonControlTemplateKey}"
                HorizontalAlignment="Center"
                Margin="24"
                Padding="10"
                FontSize="24">
                커스텀 템플리트 버튼
            </Button>
        </StackPanel>
    </Grid>
</Window>
728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요