BindingGroup.NotifyOnValidationError 屬性

定義

取得或設定值,這個值會表示當 Error 的狀態變更時,是否會發生 ValidationRule 事件。

public:
 property bool NotifyOnValidationError { bool get(); void set(bool value); };
public bool NotifyOnValidationError { get; set; }
member this.NotifyOnValidationError : bool with get, set
Public Property NotifyOnValidationError As Boolean

屬性值

Error 的狀態變更時,如果發生 ValidationRule 事件,則為 true,否則為 false。 預設為 false

範例

下列範例會 BindingGroup 建立 ,並將 設定 NotifyOnValidationErrortrue ,讓應用程式可以在失敗時 ValidationRule 處理 Validation.Error 事件。

<StackPanel.BindingGroup>
  <BindingGroup NotifyOnValidationError="True">
    <BindingGroup.ValidationRules>
      <src:ValidateDateAndPrice ValidationStep="ConvertedProposedValue" />
    </BindingGroup.ValidationRules>
  </BindingGroup>
</StackPanel.BindingGroup>

下列範例會處理 Validation.Error 事件。

// This event occurs when a ValidationRule in the BindingGroup
// or in a Binding fails.
private void ItemError(object sender, ValidationErrorEventArgs e)
{
    if (e.Action == ValidationErrorEventAction.Added)
    {
        MessageBox.Show(e.Error.ErrorContent.ToString());
    }
}
' This event occurs when a ValidationRule in the BindingGroup
' or in a Binding fails.
Private Sub ItemError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs)
    If e.Action = ValidationErrorEventAction.Added Then
        MessageBox.Show(e.Error.ErrorContent.ToString())

    End If
End Sub

備註

附加 Validation.Error 事件發生在具有 BindingGroup 的專案上。

適用於