Click here to Skip to main content
15,896,549 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
C#
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;
     }


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 .
Posted
Comments
Karthik_Mahalingam 2-Jan-14 5:31am    
did u check the "Values" ?
is this contains all "true" ??
Naz_Firdouse 2-Jan-14 5:58am    
debug your code and see what value is assigned for isValid in Values...
kumar9avinash 2-Jan-14 7:01am    
((System.Windows.Controls.ValidationError)(values[0])).BindingInError {System.Windows.Data.BindingExpression}
this value is getting stored in values
and in is valid i am geting this value=isValid {System.Windows.Controls.ValidationError}
Naz_Firdouse 2-Jan-14 8:23am    
could you share sample code to know how you are using converter?
kumar9avinash 3-Jan-14 1:02am    
i changed my loop to this and its working fine
foreach (var isValid in values)

if (isValid as ValidationError != null)
{
return false;
}
return 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;
}
 
Share this answer
 
Comments
Naz_Firdouse 3-Jan-14 8:26am    
the OP already mentioned that he made some changes and the issue is solved.
i changed my loop to this and its working fine foreach (var isValid in values) if (isValid as ValidationError != null) { return false; } return true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900