UpdateSourceExceptionFilterCallback 委托


表示处理绑定源值更新过程中引发的异常的方法。Represents the method that handles exceptions that are thrown during the update of the binding source value. 它必须与 ExceptionValidationRule 一起使用。This must be used with the ExceptionValidationRule.

public delegate System::Object ^ UpdateSourceExceptionFilterCallback(System::Object ^ bindExpression, Exception ^ exception);
public delegate object UpdateSourceExceptionFilterCallback(object bindExpression, Exception exception);
type UpdateSourceExceptionFilterCallback = delegate of obj * Exception -> obj
Public Delegate Function UpdateSourceExceptionFilterCallback(bindExpression As Object, exception As Exception) As Object 



出现异常的对象。The object with the exception.


遇到的异常。The exception encountered.



通常为下列某项的对象:An object that is typically one of the following:

“值”Value 描述Description
null 忽略任何异常。To ignore any exceptions. 默认行为(如果没有 UpdateSourceExceptionFilterCallback)是对异常创建 ValidationError 并将其添加到绑定元素的 Errors 集合。The default behavior (if there is no UpdateSourceExceptionFilterCallback) is to create a ValidationError with the exception and adds it to the Errors collection of the bound element.
任何对象Any object 创建 ValidationError 对象,并将 ErrorContent 设置为此对象。To create a ValidationError object with the ErrorContent set to that object.

ValidationError 对象添加到绑定元素的 Errors 集合中。The ValidationError object is added to Errors collection of the bound element.

一个 ValidationError 对象A ValidationError object BindingExpressionMultiBindingExpression 对象设置为 BindingInErrorTo set the BindingExpression or MultiBindingExpression object as the BindingInError. ValidationError 对象添加到绑定元素的 Errors 集合中。The ValidationError object is added to Errors collection of the bound element.


Text以下的属性 TextBox 被数据绑定到 Age3 类型为的源属性 intThe Text property of the following TextBox is data-bound to a source property Age3 that is of type int. ExceptionValidationRule检查在源属性更新过程中引发的异常,例如,当用户输入的值无法转换为整数) 时 (。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}">
    <Binding Path="Age3" Source="{StaticResource ods}"

你可以选择提供自定义逻辑来处理这些异常。You have the option to provide custom logic to handle those exceptions. 下面的示例演示如何使用 UpdateSourceExceptionFilter 属性设置 UpdateSourceExceptionFilterCallbackThe 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);

下面是的示例实现 UpdateSourceExceptionFilterCallbackThe 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.


如果已将 ExceptionValidationRule 与对象关联, Binding 则可以选择使用 UpdateSourceExceptionFilter 属性设置此回调以提供用于处理异常的自定义逻辑。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.

如果未在 Binding 上指定 UpdateSourceExceptionFilter,则绑定引擎会创建具有异常的 ValidationError 并将其添加到绑定元素的 Validation.Errors 集合中。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.



获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.