Contains a collection of bindings and ValidationRule objects that are used to validate an object.
Assembly: PresentationFramework (in PresentationFramework.dll)
Gets a collection of BindingExpression objects that contains information for each Binding in the .
Gets whether each source in the binding can discard pending changes and restore the original values.
Gets a value that indicates whether thehas a failed validation rule.
Gets or sets a value that indicates whether thecontains a proposed value that has not been written to the source.
Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject.)
Gets the sources that are used by the Binding objects in the.
Gets or sets the name that identifies the, which can be used to include and exclude Binding objects in the .
Gets the object that thisis assigned to.
Gets or sets a value that indicates whether thereuses target values that have not been committed to the source.
Gets or sets a value that indicates whether to include the NotifyDataErrorValidationRule.
Gets a collection of ValidationError objects that caused the to be invalid.
Gets a collection of ValidationRule objects that validate the source objects in the .
A Address, which has the properties, Street, City, ZipCode, and Country, with the values that the user provided. The application has a panel that contains four TextBox controls, each of which is data bound to one of the object’s properties. You can use a ValidationRule in a to validate the Address object. If the bindings participate in the same , you can ensure that the zip-code is valid for the country of the address.creates a relationship between multiple bindings, which can be validated and updated together. For example, suppose that an application prompts the user to enter an address. The application then populates an object of type
You set the BindingGroup property on FrameworkElement or FrameworkContentElement. Child elements inherit the from their parent elements, just as with any other inheritable property. A binding on a descendent element is added to a if one of the following situations occurs:
You add ValidationRule objects to a . The is passed as the first parameter of the Validate method when the ValidationRule runs. You can use the TryGetValue or GetValue(Object, String) method on that to get the proposed values of the object, and the Items property to get the sources of the bindings.
A ValidateWithoutUpdate, UpdateSources, or CommitEdit), the binding for each TextBox in the example is validated and potentially updated. When a binding is part of a , the source of the binding is not updated until you call UpdateSources or CommitEdit on the , unless you explicitly set the UpdateSourceTrigger property.updates the sources of the binding at the same time instead of each binding being updated separately. When you call one of the methods to validate the data (
The following examples create an application that prompts the user to enter the description and price of an item and the date that the offer expires. The application displays the current information for the item below the form. The user can submit or cancel the changes.
The application does the following to achieve this behavior.
Creates a StackPanel when it creates the user interface (UI) of the application.and adds it the root
The following example creates the user interface (UI) of the application. The root StackPanel has a that contains a ValidationRule that validates the item, as described previously. The binding objects on the Price property and the OfferExpires property become part of the and each binding has a ValidationRule to make sure that price and date, respectively, are valid values. The validation rules for the individual properties run before the ValidationRule on the .
The following example shows the event handlers for the application. When the user clicks the Submit button, the application calls CommitEdit to run each ValidationRule that is associated with the . If each ValidationRule succeeds, CommitEdit saves the values to the object and ends the edit transaction. If CommitEdit is successful, the application begins another edit transaction. When a ValidationRule fails, the Validation.Error event occurs because the application set NotifyOnValidationError to true on the (in the previous example). ItemError handles the Validation.Error event and displays information about the validation error to the user. The example also handles the Loaded event for the StackPanel and the Click event for the Cancel button.
The following example shows the custom ValidationRule ValidateDateAndPrice, which was added to the in the first example. The ValidationRule uses the in its Validate method to get the values the user entered into the form, and checks that if an item is over 100 dollars, it will be available for at least seven days.
Available since 3.0
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.