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

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

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"
    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>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요