码迷,mamicode.com
首页 > 其他好文 > 详细

简单的水印输入框

时间:2014-05-27 17:59:24      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:des   style   c   class   blog   code   

bubuko.com,布布扣
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; }
        }
    }

}
bubuko.com,布布扣
<btn:WaterMarkBox Width="150" Height="20" MaskText="输入想要查找的房号..."/>

 

简单的水印输入框,布布扣,bubuko.com

简单的水印输入框

标签:des   style   c   class   blog   code   

原文地址:http://www.cnblogs.com/Events/p/3752868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!