Export (0) Print
Expand All

UpdateSourceExceptionFilterCallback Delegate

Represents the method that handles exceptions that are thrown during the update of the binding source value. This must be used with the ExceptionValidationRule.

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

public delegate Object UpdateSourceExceptionFilterCallback(
	Object bindExpression,
	Exception exception
)

Parameters

bindExpression
Type: System.Object

The object with the exception.

exception
Type: System.Exception

The exception encountered.

Return Value

Type: System.Object
An object that is typically one of the following:

Value

Description

null

To ignore any exceptions. The default behavior (if there is no UpdateSourceExceptionFilterCallback) is to create a ValidationError with the exception and adds it to the Validation.Errors collection of the bound element.

Any object

To create a ValidationError object with the ErrorContent set to that object.

The ValidationError object is added to Validation.Errors collection of the bound element.

A ValidationError object

To set the BindingExpression or MultiBindingExpression object as the BindingInError. The ValidationError object is added to Validation.Errors collection of the bound element.

If you have associated the ExceptionValidationRule with your Binding object you have the option to use the UpdateSourceExceptionFilter property to set this callback to provide custom logic for handling the exceptions. This callback is invoked whenever any exception is encountered when the binding engine updates the binding source value.

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.

The Text property of the following TextBox is data-bound to a source property Age3 that is of type int. The ExceptionValidationRule checks for exceptions that are thrown during the update of the source property (such as when the user enters a value that cannot be converted to an integer).

<TextBox Name="textBox3" Width="50" FontSize="15"
         Grid.Row="4" Grid.Column="1" Margin="2"
         Validation.ErrorTemplate="{StaticResource validationTemplate}"
         Style="{StaticResource textBoxInError}">
  <TextBox.Text>
    <Binding Path="Age3" Source="{StaticResource ods}"
             UpdateSourceTrigger="PropertyChanged">
      <Binding.ValidationRules>
        <ExceptionValidationRule/>
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>

You have the option to provide custom logic to handle those exceptions. The following example shows how to use the UpdateSourceExceptionFilter property to set an UpdateSourceExceptionFilterCallback:


BindingExpression myBindingExpression = textBox3.GetBindingExpression(TextBox.TextProperty);
Binding myBinding = myBindingExpression.ParentBinding;
myBinding.UpdateSourceExceptionFilter = new UpdateSourceExceptionFilterCallback(ReturnExceptionHandler);
myBindingExpression.UpdateSource();

The following is an example implementation of an UpdateSourceExceptionFilterCallback:

object ReturnExceptionHandler(object bindingExpression, Exception exception)
{
    return "This is from the UpdateSourceExceptionFilterCallBack.";
}

For the complete sample, see Binding Validation Sample.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft