public ref class ValidationError
public class ValidationError
type ValidationError = class
Public Class ValidationError
The following example shows a style trigger that creates a ToolTip that reports a validation error message. The Validation.Errors attached property returns a collection of ValidationError objects on the bound element.
<Style x:Key="textStyleTextBox" TargetType="TextBox">
<Setter Property="Foreground" Value="#333333" />
<Setter Property="MaxLength" Value="40" />
<Setter Property="Width" Value="392" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
The WPF data binding model enables you to associate validation rules with your Binding object. Validation occurs during target-to-source value transfer before the converter is called. The following describes the validation process.
When a value is being transferred from the target property to the source property, the data binding engine first removes any ValidationError that might have been added to the Validation.Errors attached property of the bound element. It then checks whether any custom validation rules are defined for that Binding, in which case it calls the Validate method on each ValidationRule until one of them fails or until all of them pass.
Once there is a custom rule that does not pass, the binding engine creates a ValidationError object and adds it to the Validation.Errors collection of the bound element. When Validation.Errors is not empty, the Validation.HasError attached property of the element is set to true
. Also, if the NotifyOnValidationError property of the Binding is set to true
, then the binding engine raises the Validation.Error attached event on the element.
If all the rules pass, the binding engine then calls the converter, if one exists.
If the converter passes, the binding engine calls the setter of the source property.
If the binding has an ExceptionValidationRule associated with it and an exception is thrown during step 3 or 4, the binding engine checks to see if there is an UpdateSourceExceptionFilter. You can use the UpdateSourceExceptionFilter callback to provide a custom handler for handling exceptions. If an UpdateSourceExceptionFilter is not specified on the Binding, the binding engine creates a ValidationError with the exception and adds it to the Validation.Errors collection of the bound element.
A valid value transfer in either direction (target to source or source to target) will clear the Validation.Errors attached property.
Constructors Properties Methods See alsoCollaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4