WPF TextBox提示文字设定

 

WPF TextBox框提示文字,鼠标划入提示文字消失

<TextBox
Width="248"
VerticalContentAlignment="Center"
BorderThickness="0"
CaretBrush="White">
<TextBox.Resources>
<VisualBrush
x:Key="HintText"
AlignmentX="Left"
Opacity="0.5"
Stretch="None"
TileMode="None">
<VisualBrush.Visual>
<TextBlock
FontSize="12"
Foreground="White"
Text="{DynamicResource MsgUser}" />
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Resources>
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource HintText}" />
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="{StaticResource HintText}" />
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="Background" Value="Transparent" />
</Trigger>
<!--<EventTrigger RoutedEvent="TextBox.PreviewTextInput" />-->
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>

 

posted @ 2017-09-21 11:19  风来风往风伤(TiAmo)  阅读(1376)  评论(0编辑  收藏  举报