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
)
/** @delegate */
public delegate Object UpdateSourceExceptionFilterCallback (
	Object bindExpression, 
	Exception exception
)
In XAML, you can use delegates but you cannot define your own.

Parameters

bindExpression

The object with the exception.

exception

The exception encountered.

Return Value

An object that is typically one of the following:

Value

Description

a null reference (Nothing in Visual Basic)

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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft