Willem
Willem

Reputation: 9476

How to make ValidatesOnDataErrors bindable?

I have to need to bind the value of ValidatesOnDataErrors, so that it can be determined at run-time.

The reason for this, is because i don't always want to validate the data.

This is a property of a binding so i know i CANT do this:

"{Binding Path=SomePath, ValidatesOnDataErrors={Binding Path=SomeBoolProperty}}"

So my question is, how would i change my binding so that the value of ValidatesOnDataErrors, can be determined at run-time.

NOTE: I want to keep the binding in the ViewModel. I don't want to set anything in the View's code behind.

Upvotes: 1

Views: 579

Answers (1)

mathieu
mathieu

Reputation: 31202

Implement this logic inside your ViewModel, and make it implement the IDataErrorInfo interface.

When no validation is required, make the properties :

string Error { get; }
string this[string columnName] { get; }

return an empty string;

As a bonus, this behavior will be easily testable.

Upvotes: 2

Related Questions