WPF 带有提示文本的透明文本框

 1 <TextBox Text="{Binding SearchInfo, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0"  MaxLength="20" BorderThickness="0">
 2                                 <TextBox.Resources>
 3                                     <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Center">
 4                                         <VisualBrush.Visual>
 5                                             <TextBlock FontStyle="Italic" Text="搜索"/>
 6                                         </VisualBrush.Visual>
 7                                     </VisualBrush>
 8                                 </TextBox.Resources>
 9                                 <TextBox.Style>
10                                     <Style TargetType="TextBox">
11                                         <Setter Property="Height" Value="25px"/>
12                                         <Setter Property="VerticalContentAlignment" Value="Center"/>
13                                         <Setter Property="HorizontalContentAlignment" Value="Center"/>
14                                         <Setter Property="Background" Value="Transparent"/>
15                                         <Style.Triggers>  
16                                             <Trigger Property="Text" Value="{x:Null}">
17                                                 <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
18                                             </Trigger>
19                                             <Trigger Property="Text" Value="">
20                                                 <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
21                                             </Trigger>
22                                         </Style.Triggers>
23                                     </Style>
24                                 </TextBox.Style>
25                             </TextBox>
原文地址:https://www.cnblogs.com/dyfisgod/p/8558726.html