Suppose I have 3 fields on a Silverlight based xaml page
Color, Size and SurpriseMe
where none of the fields are required and SurpriseMe is a checkbox initially set to checked.
I want to create the following behavior:
-
When SurpriseMe is cleared,
- Display the required field data annotations for Color and Size
- Enforce the required Validation
-
When SurpriseMe is checked,
- Remove the required field data annotation
- remove the restriction
Is there any easy way to do this?
You need to provide custom validation (see
CustomValidationAttribute). You can roll your own or use a library like Fluent Validation.