Errors Attached Property

Validation.Errors Attached Property


Gets the collection of all active ValidationError objects on the bound element.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

See GetErrors

Property Value

Type: System.Collections.ObjectModel.ReadOnlyObservableCollection<ValidationError>

A read-only collection of all active ValidationError objects on the bound element. The default is an empty collection.

The application cannot modify the content of this collection. See the Example section for an example of how to use this .GTMT

The WPF data binding model enables you to associate ValidationRules with your Binding object. Validation occurs during -to- value transfer before the converter is called. The following describes the validation process:GTMTGTMT

  1. When a value is being transferred from the target property to the source property, the data binding engine first removes any ValidationError that may have been added to the Validation.Errors  of the bound element. It then checks if there are any custom ValidationRules defined for that Binding, in which case it calls the Validate method on each of the ValidationRules until one of them runs into an error or until all of them pass.GTMT

  2. 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  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  on the element.GTMTGTMT

  3. If all of the rules pass, the binding engine then calls the converter, if one exists.

  4. If the converter passes, the binding engine calls the setter of the source property.

  5. If the binding has an ExceptionValidationRule associated with it and an exception is thrown during step 4, the binding engine checks to see if there is a UpdateSourceExceptionFilter. You have the option to 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.

Also note that a valid value transfer in either direction (target-to-source or source-to-target) clears the Validation.Errors.GTMT

For information about the behavior of this property in MultiBinding scenarios, see ValidationError.

For more information, see "Data Validation" in Data Binding Overview.

See Remarks. The Errors collection itself is not user settable, but you can use it in a control template definition in XAML.

Identifier field


Metadata properties set to true


Return to top
© 2015 Microsoft