Win8 在TextBox中设置提示信息,当TextBox获得焦点时消失,失去时验证

// 在获得焦点时,验证文本内容是否与提示信息相同,相同则清除,并改变文本颜色

private void email_GotFocus(object sender, RoutedEventArgs e)
        {
            if (this.email.Text.Equals("[email protected]"))
            {
                this.email.Text = "";
            }
            this.email.Foreground = new SolidColorBrush(Colors.Black);
        }



// 在失去焦点时,验证文本内容是否为空(清除空格),为空则重新设置提示信息,并改变颜色

private void email_LostFocus(object sender, RoutedEventArgs e)
        {
            if (0 == this.email.Text.Trim().Length)
            {
                this.email.Text = "[email protected]";
                this.email.Foreground = new SolidColorBrush(Colors.Gray);
            }
        }



//  效果图


你可能感兴趣的:(Win8 在TextBox中设置提示信息,当TextBox获得焦点时消失,失去时验证)