首页 > 代码库 > 简单的水印输入框
简单的水印输入框
using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WisHotel { public class WaterMarkBox : TextBox { #region MaskText /// <summary> /// view sort style, desc arrow /// </summary> public static readonly DependencyProperty MaskTextProperty = DependencyProperty.Register("MaskText", typeof(string), typeof(WaterMarkBox)); public string MaskText { get { return (string)GetValue(MaskTextProperty); } set { SetValue(MaskTextProperty, value); } } #endregion public WaterMarkBox() { Loaded += (sender, args) => { if (string.IsNullOrEmpty(base.Text)) { base.Text = MaskText; base.Foreground = Brushes.Gray; } }; base.GotFocus += (sender, args) => { base.Foreground = Brushes.Black; if (base.Text == MaskText) base.Text = string.Empty; }; base.LostFocus += (sender, args) => { if (!string.IsNullOrEmpty(base.Text)) return; base.Text = MaskText; base.Foreground = Brushes.Gray; }; } public new string Text { get { if (base.Text == MaskText) return string.Empty; else return base.Text; } set { base.Text = value; } } } }
<btn:WaterMarkBox Width="150" Height="20" MaskText="输入想要查找的房号..."/>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。