英語で読む

次の方法で共有


Binding.UpdateSourceExceptionFilter プロパティ

定義

バインディング ソースの値の更新時にバインディング エンジンが検出した例外を処理するためにカスタム ロジックの提供に使用できるハンドラーを取得または設定します。 これは、バインディングに ExceptionValidationRule を関連付けている場合にのみ適用できます。

public System.Windows.Data.UpdateSourceExceptionFilterCallback UpdateSourceExceptionFilter { get; set; }

プロパティ値

バインディング ソースの値の更新時にバインディング エンジンが検出した例外を処理するためのカスタム ロジックを提供するメソッド。

TextTextBoxの プロパティは、 型intのソース プロパティAge3にデータ バインドされます。 は ExceptionValidationRule 、ソース プロパティの更新中にスローされる例外をチェックします (たとえば、ユーザーが整数に変換できない値を入力したときなど)。

<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>

これらの例外を処理するカスタム ロジックを提供できます。 次の例は、 プロパティを使用して を UpdateSourceExceptionFilter 設定する方法を UpdateSourceExceptionFilterCallback示しています。


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

の実装例を次に UpdateSourceExceptionFilterCallback示します。

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

UpdateSourceExceptionFilterCallback、例外自体、または をValidationErrornullすこともできます。 詳細については、「UpdateSourceExceptionFilterCallback」を参照してください。

完全なサンプルについては、「 バインド検証のサンプル」を参照してください。

注釈

ExceptionValidationRuleは、バインディング ソース プロパティの更新中にスローされた例外をチェックする組み込みの検証規則です。 オブジェクトに をExceptionValidationRuleBinding関連付けた場合は、このプロパティを使用して、これらの例外を処理するためのカスタム ロジックを提供するハンドラーを設定できます。 BindingUpdateSourceExceptionFilter が指定されていない場合、バインディング エンジンは例外を使用して ValidationError を作成し、バインドされた要素の Validation.Errors コレクションに追加します。

適用対象

製品 バージョン
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10