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>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-11-28
  • 2022-12-23
  • 2021-12-24
猜你喜欢
  • 2021-09-29
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
相关资源
相似解决方案