<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内容。

最新文章

  1. Python字典的基本组成以及用法
  2. MySql中文乱码
  3. MySQL INSERT插入条件判断:如果不存在则插入
  4. uva11292 Dragon of Loowater
  5. Windows Server 2016
  6. struct socket 结构详解
  7. hehe
  8. HTML5中的Range对象的研究
  9. Android IOS WebRTC 音视频开发总结(十二)-- sufaceview
  10. CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
  11. UVa 839 (递归方式读取二叉树) Not so Mobile
  12. mina高并发短连接导致java.io.IOException: Too many open files解决方案
  13. [转]PLS-S-00201, identifier &#39;CALLDEMO.GET_EMPLOYEES&#39; must be declared 预编译错误原因及解决办法
  14. 正则表达式30分钟入门教程&lt;转载&gt;
  15. 写给新入IT的新人们
  16. libc.so.6 误删后修复
  17. .NET Core开源API网关 – Ocelot中文文档
  18. SQL 存储过程中事务回滚
  19. 【原创】VirtualBox 磁盘扩容教程
  20. python多继承中子类访问祖先类的同名成员

热门文章

  1. HDUOJ----(1084)What Is Your Grade?
  2. 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)
  3. SPFA 上手题 数 枚:
  4. Python学习笔记014——生成器Generator
  5. asp.net core mvc视频A:笔记3-7.ViewStart与ViewImort
  6. [Android实例] 拖动滑块进行图片拼合验证方式的实现
  7. Unix环境高级编程(八)进程关系
  8. Python tan() 函数
  9. CTPN - 训练
  10. Mongodb 与 Mongoose 的使用