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

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

TestProject.zip
0.00MB

▶ 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="TestProject"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Color x:Key="DisabledForegroundColorKey">#ff888888</Color>
        <Style x:Key="LabelStyleKey" TargetType="Label">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment"   Value="Top"  />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Label">
                        <Border>
                            <ContentPresenter
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                RecognizesAccessKey="True" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground">
                                    <Setter.Value>
                                        <SolidColorBrush Color="{DynamicResource DisabledForegroundColorKey}" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <StackPanel
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Label
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            FontSize="48"
            FontWeight="Bold"
            IsEnabled="False"
            Content="icodebroker.tistory.com" />
        <Label
            Style="{StaticResource LabelStyleKey}"
            Margin="0 10 0 0"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            FontSize="48"
            FontWeight="Bold"
            IsEnabled="False"
            Content="icodebroker.tistory.com" />
    </StackPanel>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요