■ ControlTemplate 엘리먼트를 사용해 PasswordBox 엘리먼트를 정의하는 방법을 보여준다.
▶ 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 |
<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" Background="Green" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Color x:Key="ControlLightColorKey">White</Color> <Color x:Key="BorderMediumColorKey">#ff888888</Color> <Style x:Key="{x:Type PasswordBox}" TargetType="{x:Type PasswordBox}"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="MinWidth" Value="120" /> <Setter Property="MinHeight" Value="20" /> <Setter Property="AllowDrop" Value="true" /> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="KeyboardNavigation.TabNavigation" Value="None" /> <Setter Property="PasswordChar" Value="*" /> <Setter Property="FontFamily" Value="Verdana" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type PasswordBox}"> <Border Name="border" CornerRadius="2" BorderThickness="1" Padding="2"> <Border.Background> <SolidColorBrush Color="{DynamicResource ControlLightColorKey}" /> </Border.Background> <Border.BorderBrush> <SolidColorBrush Color="{DynamicResource BorderMediumColorKey}" /> </Border.BorderBrush> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal" /> <VisualState Name="Disabled" /> <VisualState Name="MouseOver" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <ScrollViewer Name="PART_ContentHost" /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <PasswordBox HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" PasswordChar="#" /> </Window> |