첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="TextBox 엘리먼트 : 워터마크 텍스트 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style x:Key="WatermarkTextBoxKey">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Grid>
                            <aero:ListBoxChrome Name="listBoxChrome"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding Border.BorderBrush}"
                                Background="{TemplateBinding Panel.Background}"
                                RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}"
                                RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}"
                                SnapsToDevicePixels="True">
                                <ScrollViewer Name="PART_ContentHost"
                                    SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </aero:ListBoxChrome>
                            <Label Name="watermarkLabel"
                                Content="{TemplateBinding Tag}"
                                Visibility="Collapsed"
                                Focusable="False"
                                Foreground="Gray"
                                Background="Transparent" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsFocused" Value="False" />
                                    <Condition Property="Text"      Value=""      />
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter
                                        TargetName="watermarkLabel"
                                        Property="Visibility"
                                        Value="Visible" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <Trigger Property="UIElement.IsEnabled" Value="False">
                                <Setter
                                    TargetName="listBoxChrome"
                                    Property="Panel.Background"
                                    Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                <Setter
                                    Property="TextElement.Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel VerticalAlignment="Center">
            <TextBox
                Style="{StaticResource WatermarkTextBoxKey}"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="300"
                Height="25"
                HorizontalContentAlignment="Left"
                VerticalContentAlignment="Center"
                Tag="ID를 입력해 주시기 바랍니다."
                Text="" />
            <TextBox
                Style="{StaticResource WatermarkTextBoxKey}"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Margin="0 10 0 0"
                Width="300"
                Height="25"
                HorizontalContentAlignment="Left"
                VerticalContentAlignment="Center"
                Tag="패스워드를 입력해 주시기 바랍니다."
                Text="" />
        </StackPanel>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요