在验证wpf中的多个文本框时遇到问题 [英] having issue in validation more than one textbox in wpf

查看:46
本文介绍了在验证wpf中的多个文本框时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i尝试通过wpf中的i multivalueconverter验证多个文本框,我已将此文本框绑定到按钮的isenabled属性,如果有任何错误按钮应该被禁用。 />

$ b $我在班上遇到这种情况

Hi,
i am trying to validate more than one textbox through i multivalueconverter in wpf , i have binded this textbox to isenabled property of button , if there is any error button should get disabled.

i am having this condition in my class

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
     {
         foreach (var isValid in values)
             if (isValid as bool? == false)
             {
                 return false;
             }
         return true;
     }





我已经通过验证规则类进行了验证,但我认为上述条件存在一些问题时间它只返回true.it dosent进入if condtion并返回false。



and i have done validation through validation rule class , but i think there is some issue with the above condition every time it return true only.it dosent get inside the if condtion and return false .

推荐答案

试试这个并告诉我结果。





公共对象转换(object []值,类型targetType,对象参数,CultureInfo文化)

{

foreach(var isValid in values)



if(isValid!= DependencyProperty.UnsetValue && isValid!= null)

{

if(isValid as bool?== false)

{

返回false;

}



}

返回true;

}
Try this one and tell me the outcome.


public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (var isValid in values)

if (isValid != DependencyProperty.UnsetValue && isValid !=null)
{
if (isValid as bool? == false)
{
return false;
}

}
return true;
}


i changed my loop to this and its working fine foreach (var isValid in values) if (isValid as ValidationError != null) { return false; } return true;


这篇关于在验证wpf中的多个文本框时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆