VoodooChild
VoodooChild

Reputation: 9784

Set a ValidationError by Code in ViewModel

I came across Set a ValidationError by Code, by Christian Mosers

ValidationError validationError = new ValidationError(regexValidationRule, 
    textBox.GetBindingExpression(TextBox.TextProperty));

validationError.ErrorContent = "This is not a valid e-mail address";

Validation.MarkInvalid(textBox.GetBindingExpression(TextBox.TextProperty), 
    validationError);

How can I use this in my ViewModel?

Upvotes: 0

Views: 553

Answers (1)

brunnerh
brunnerh

Reputation: 184526

There are other ways to get errors out of the VM, for example by implementing IDataErrorInfo or by throwing exceptions in setters (the binding then needs to validate on exception).

Upvotes: 3

Related Questions