(Temporarily) Disable verification in WPF

When a class implements the IDataErrorInfo interface, and this class is part of the form binding, is there a way to temporarily disable the validation associated with the binding?

For example, if I do not want to allow blank lines in the property of my class, when the form opens, the associated control is marked as having an error (with a red border by default). I think it’s a little clumsy to immediately mark the input as having an error (before the user even has a chance to enter something). Is there any way around this?

I searched most of the day, but I seem to be coming up with how to disable the submit button until all the data is valid (which is actually not what I do).

+5
source share
1 answer

You have a flag in the class that implements IDataErrorInfo, which controls when validation is performed. DoValiation;

When the flag is false, you should report IDataErrorInfo that there are no errors (i.e. returns null, etc.).

During an intialisation view, you must set the DoValidation flag to false in your model, and then let the view do all the bindings to your data.

After the View is Loaded, you must set the DoValidation flag to true .... from this point ... data changes will cause error indicators to appear if the values ​​are still not valid.

See this other post for more details on how to structure IDataErrorInfo code:

+3
source

All Articles