WPF ValidationRule when control IsEnabled=false

validationwpf

how do I add a ValidationRule to my control that only fires when the control is enabled?

Thanks.

Best Solution

Have a look here, look under the 'Custom validation rules' and you could check it in the public override ValidationResult Validate method.

Just do

if (mytextbox.IsEnabled) {// validate here}

EDIT:

So, instead of doing your validation rule binding in XAML, I think you'll need to do it in your code behind, and there you can assign a property you've created in your custom validation rule class to your current instance of your combobox, and then use that in your override of your Validate method.

So in your validationrule class

public ComboBox MyCombo
{
     get;
     set;
}

then when doing your validation rule binding

myvalidationinstance.MyCombo = mycombobox;

now you can use your MyCombo property in the Validate method to check IsEnabled