ExceptionValidationRule ExceptionValidationRule ExceptionValidationRule ExceptionValidationRule Class

Definition

Represents a rule that checks for exceptions that are thrown during the update of the binding source property.

public ref class ExceptionValidationRule sealed : System::Windows::Controls::ValidationRule
public sealed class ExceptionValidationRule : System.Windows.Controls.ValidationRule
type ExceptionValidationRule = class
    inherit ValidationRule
Public NotInheritable Class ExceptionValidationRule
Inherits ValidationRule
Inheritance
ExceptionValidationRuleExceptionValidationRuleExceptionValidationRuleExceptionValidationRule

Examples

The ValidationRules property takes a collection of ValidationRule objects. The following example uses TextBox.Text as the binding target property and StartPrice (an integer) as the binding source property. When the user enters a value that cannot be converted to an integer, an exception is thrown, which causes the ExceptionValidationRule to invalidate the target value.

<TextBox Name="StartPriceEntryForm" Grid.Row="2" Grid.Column="1"
    Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5">
  <TextBox.Text>
    <Binding Path="StartPrice" UpdateSourceTrigger="PropertyChanged">
      <Binding.ValidationRules>
        <ExceptionValidationRule />
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>

By default, when there is a validation error, the TextBox appears with a red border. Optionally, you can write a custom ErrorTemplate to specify how you want to notify the user when there is a validation error.

For more information about data validation, see Data Binding Overview.

For the complete sample, see Data Binding Demo.

Remarks

The WPF data binding model enables you to associate ValidationRules with a Binding object. The ExceptionValidationRule class is a built-in rule that checks for exceptions that are thrown during the updates of the binding source property. You can provide custom logic to specify how the binding engine handles these exceptions by using a UpdateSourceExceptionFilterCallback. For more information, see UpdateSourceExceptionFilter.

An alternative syntax to setting the ExceptionValidationRule explicitly is to set the ValidatesOnExceptions property to true on your Binding or MultiBinding object.

You can create a custom rule by creating a class that derives from ValidationRule. For more information and a detailed discussion of data validation, see Data Binding Overview.

Constructors

ExceptionValidationRule() ExceptionValidationRule() ExceptionValidationRule() ExceptionValidationRule()

Initializes a new instance of the ExceptionValidationRule class.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
Validate(Object, CultureInfo) Validate(Object, CultureInfo) Validate(Object, CultureInfo) Validate(Object, CultureInfo)

Performs validation checks on a value.

Validate(Object, CultureInfo, BindingExpressionBase) Validate(Object, CultureInfo, BindingExpressionBase) Validate(Object, CultureInfo, BindingExpressionBase) Validate(Object, CultureInfo, BindingExpressionBase)

Performs validation checks on a value.

(Inherited from ValidationRule)
Validate(Object, CultureInfo, BindingGroup) Validate(Object, CultureInfo, BindingGroup) Validate(Object, CultureInfo, BindingGroup) Validate(Object, CultureInfo, BindingGroup)

Performs validation checks on a value.

(Inherited from ValidationRule)

Properties

ValidatesOnTargetUpdated ValidatesOnTargetUpdated ValidatesOnTargetUpdated ValidatesOnTargetUpdated

Gets or sets a value that indicates whether the validation rule runs when the target of the Binding is updated.

(Inherited from ValidationRule)
ValidationStep ValidationStep ValidationStep ValidationStep

Gets or sets when the validation rule runs.

(Inherited from ValidationRule)

Applies to

See Also