【WPF】设置TextBox内容为空时的提示文字
2024-08-21 06:03:25
<TextBox Width="150" Margin="5">
<TextBox.Resources>
<VisualBrush x:Key="HintText" 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 HintText}"/>
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="Background" Value="{StaticResource HintText}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
运行效果:
注意点:
- 不可直接设置TextBox的Text内容,否则将一直使用该Text内容。
最新文章
- Python字典的基本组成以及用法
- MySql中文乱码
- MySQL INSERT插入条件判断:如果不存在则插入
- uva11292 Dragon of Loowater
- Windows Server 2016
- struct socket 结构详解
- hehe
- HTML5中的Range对象的研究
- Android IOS WebRTC 音视频开发总结(十二)-- sufaceview
- CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
- UVa 839 (递归方式读取二叉树) Not so Mobile
- mina高并发短连接导致java.io.IOException: Too many open files解决方案
- [转]PLS-S-00201, identifier &#39;CALLDEMO.GET_EMPLOYEES&#39; must be declared 预编译错误原因及解决办法
- 正则表达式30分钟入门教程<;转载>;
- 写给新入IT的新人们
- libc.so.6 误删后修复
- .NET Core开源API网关 – Ocelot中文文档
- SQL 存储过程中事务回滚
- 【原创】VirtualBox 磁盘扩容教程
- python多继承中子类访问祖先类的同名成员
热门文章
- HDUOJ----(1084)What Is Your Grade?
- 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)
- SPFA 上手题 数 枚:
- Python学习笔记014——生成器Generator
- asp.net core mvc视频A:笔记3-7.ViewStart与ViewImort
- [Android实例] 拖动滑块进行图片拼合验证方式的实现
- Unix环境高级编程(八)进程关系
- Python tan() 函数
- CTPN - 训练
- Mongodb 与 Mongoose 的使用