我正在尝试向2 PasswordBoxes添加一些验证规则。两个密码都必须超过5个字符,并且两个密码必须匹配。我目前没有使用MVVM。
我想我可以检查PasswordChanged事件的密码,但是我不能让无效状态切换到这些框。
有谁有这样的例子吗?
发布于 2011-05-03 01:24:44
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));
}
}https://stackoverflow.com/questions/3267461
复制相似问题