■ ControlTemplate 엘리먼트를 사용해 Label 엘리먼트를 정의하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<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> |