https://code.4noobz.net/wpf-add-a-watermark-to-a-native-wpf-textbox/
WPF - Add a Watermark to a native WPF TextBox - Code4Noobz
This is how to add a Watermark to a native WPF TextBox without using a control from another toolkit. The concept is to create a Style which will add a new property (called Tag) for your TextBoxes. The content of this Tag will be the watermark. And it wil
code.4noobz.net
<Window.Resources>
<Style x:Key="MyWaterMarkStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Border Background="White" BorderBrush="#FF7D8683" BorderThickness="1"/>
<ScrollViewer x:Name="PART_ContentHost" Margin="5,0,0,0" VerticalAlignment="Center" />
<Label Margin="5,0,0,0" x:Name="WaterMarkLabel" Content="{TemplateBinding Tag}" VerticalAlignment="Center"
Visibility="Collapsed" Foreground="Gray" FontFamily="Arial"/>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value=""/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="WaterMarkLabel" Value="Visible"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="DimGray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid >
<TextBox Style="{StaticResource MyWaterMarkStyle}" Height="25" Tag="Please write something here!"/>'C#(.Net)' 카테고리의 다른 글
| [시작하세요 C# 12 프로그래밍 ] #3 CSharp 기초 (0) | 2025.03.04 |
|---|---|
| DependencyProperty 란? (0) | 2024.10.24 |
| wpf 참조 (0) | 2021.08.01 |
| WPF) 아날로그시계( c# 200제) (0) | 2021.07.21 |
| C# 기본 get, set (c++ getter, setter) (0) | 2021.07.13 |