WPF文本框中加提示语
效果:
WPF中貌似不能像winfrom里一样直接加提示语,需要使用TextBox.Style,将Trigger标签插入进去。
贴源码:
<WrapPanel Name="TakeOverExpressNo1">
<Label Content="物流单号:"></Label>
<TextBox Grid.Row="9" Grid.Column="1" x:Name="txtTakeOverExpressNo1" Width="250" KeyDown="txtTakeOverExpressNo1_KeyDown">
<TextBox.Resources>
<VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.5" Stretch="None" AlignmentX="Left">
<VisualBrush.Visual>
<TextBlock FontStyle="Italic" Text="输入后请按回车"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Resources>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</WrapPanel>
原文地址:https://blog.csdn.net/qq_51462774/article/details/139866585
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!