입력 값이 없는 경우 DataTrigger 를 이용해 공백인 경우 문자를 표시하여 PlaceHolder 처럼 표시합니다.
<Window x:Class="PlaceHolder.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="86.638" Width="227.155">
<StackPanel>
<Grid>
<TextBox Name="searchTextBox" Margin="10" Text="" Width="180" Height="32" HorizontalAlignment="Left" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
<TextBlock Text="Search Name.." IsHitTestVisible="False" VerticalAlignment="Center" Margin="15,10,10,10" HorizontalAlignment="Left">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Hidden"/>
<Setter Property="Foreground" Value="Gray"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=searchTextBox}" Value="">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</StackPanel>
</Window>
WPF Background="{x:Null}" Background="Transparent" 차이 (0) | 2024.08.13 |
---|---|
WPF UpdateSourceTrigger란? (0) | 2024.08.13 |
WPF DataContext 의 특정 Command 를 찾아 실행하기 (0) | 2024.07.25 |
WPF MultiBinding 사용하기 (0) | 2024.07.25 |
WPF RelativeSource 간단 설명 (0) | 2024.07.25 |