|
Set a ValidationError by Code
A ValidatioRule in a BindingExpression only triggers, when the target side of the binding changes. If you want to set a validation error by code you can use the following snippet.
Set the validation error
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);
Clear the validation error
Validation.ClearInvalid(textBox.GetBindingExpression(TextBox.TextProperty));
Comments on this article
Show all comments
 |
| Christian | |
|
| Commented on 3.March 2009 |
| Don't have much help for a beginner like me.
|
|
|
 |
| Alexandra | |
|
| Commented on 19.March 2009 |
| Great tip, this helped me a lot! Keep 'em coming!
|
|
|
 |
| Yuri | |
|
| Commented on 19.April 2009 |
| What is it - regexValidationRule?
|
|
|
 |
| Gergely... | |
|
| Commented on 12.November 2009 |
| Regular Expression ... Google.com :)
|
|
|
 |
| balwat singh | |
|
| Commented on 21.April 2010 |
who to use validation inside WPF.
|
|
|
 |
| ashish | |
|
| Commented on 3.August 2010 |
| wha the fuck is this ?
|
|
|
 |
| hi | |
|
| Commented on 7.August 2010 |
| chethi venna mudda chengal malthadu
|
|
|
 |
| Christian MOSER | |
|
| Commented on 23.August 2010 |
| I apprieciate your feedback but I cant explain it anymore in depth because I just copy and pasted this from another website
|
|
|
|