첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 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 엘리먼트 : RelativeSource 태그 확장에서 TemplatedParent 모드 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border"
                            BorderThickness="2"
                            BorderBrush="Black"
                            CornerRadius="20">
                            <Border.Background>
                                <LinearGradientBrush
                                    StartPoint="0 0.5" 
                                    EndPoint="1 0.5">
                                    <GradientStop
                                        Offset="0.0"
                                        Color="{Binding Background.Color, RelativeSource={RelativeSource TemplatedParent}}" />
                                    <GradientStop Offset="0.9" Color="White" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <ContentPresenter 
                                Margin="2"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                RecognizesAccessKey="True" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter TargetName="border" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush
                                            StartPoint="0 0.5" 
                                            EndPoint="1 0.5">
                                            <GradientStop
                                                Offset="0.0"
                                                Color="{Binding Background.Color, RelativeSource={RelativeSource TemplatedParent}}" />
                                            <GradientStop Offset="0.9" Color="DarkSlateGray" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Button
            Width="300"
            Height="300"
            Background="RoyalBlue"
            FontWeight="Bold"
            FontSize="18">
            <TextBlock FontSize="48">
                테스트
            </TextBlock>
        </Button>
    </Grid>
</Window>
728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요