首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF PasswordBox验证

WPF PasswordBox验证
EN

Stack Overflow用户
提问于 2010-07-17 01:37:23
回答 1查看 2.2K关注 0票数 0

我正在尝试向2 PasswordBoxes添加一些验证规则。两个密码都必须超过5个字符,并且两个密码必须匹配。我目前没有使用MVVM。

我想我可以检查PasswordChanged事件的密码,但是我不能让无效状态切换到这些框。

有谁有这样的例子吗?

EN

回答 1

Stack Overflow用户

发布于 2011-05-03 01:24:44

代码语言:javascript
复制
    private void passwordBox2_PasswordChanged(object sender, RoutedEventArgs e)
    {
         if (passwordBox2.Password != passwordBox1.Password)
         {
             //Execute code to alert user passwords don't match here.
             passwordBox2.Background = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
         }
         else
         {
             /*You must make sure that whatever you do is reversed here;
              *all users will get the above "error" whilst typing in and you need to make sure
              *that it goes when they're right!*/
             passwordBox2.Background = new SolidColorBrush(Color.FromArgb(255,0,0,0));
          }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3267461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档