tags:

views:

136

answers:

1

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

Thanks.

+1  A: 

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

Tony
OK, so I've got a validationRule on the ComboBox's SelectedValue property to check if the value is null.How do I get a handle on the control itself in the validationRule. As far as I can see you just have the value object which, in my case, is going to be the SelectedValue. Thanks
obaylis
See my edit above
Tony
I see what you mean. Didn't think of doing the binding in code.Thanks for your reply.
obaylis