I am having a difficult finding out how to do a conditional required validation.
Basically I have an dialog object that needs to be validated. It has a bool which determines a certain state of the dialog.
If that state is true then a property needs to be validated, if it is false then the property is not used and thus needs no validation. At the same time I would like to retain the standard validation behavior when a value is not valid, namely the red border around the control that the property is bound to.
Example code on what I got:
public class Dialog
{
public bool UseValidation { get; set; }
[Required]
[StringLength(15)]
public string NotNullString { get; set; }
}
The reason for this is that I want to validate the dialog when the OK button is pressed, thus using the Validator.TryValidateObject()
method.