views:

69

answers:

3

Hi,

I have a XAML with about 100 controls. All of them are bound to class Student.

I can validate such pool like Age, or Name, but how to validate controls,which user not even touch ?

For example for field Address.

Address couldn't be null, but user forgot about filling this control.

+2  A: 

There is something called ValidationRule in WPF. You should try googling for this or if you got the Book "WPF Unleashed" look after page 298.

KroaX
+1  A: 

Set ValidatesOnTargetUpdated to true on your ValidationRule and it will run when the binding is initialized instead of only when the user modifies the data.

You could also have your Student class implement IDataErrorInfo and set ValidatesOnDataErrors=True on your Bindings. This uses DataErrorValidationRule, which has ValidatesOnTargetUpdated set.

Quartermeister
+1  A: 

There is a cool library called FluentValidation, http://fluentvalidation.codeplex.com/, it has a bunch of ValidationRules built in and makes it really easy to implement new ones. This was intended as a comment, but alas I have not enough points...

hkon