BindingGroup.NotifyOnValidationError 属性

定义

获取或设置在 Error 的状态更改时是否发生 ValidationRule 事件。Gets or sets whether the Error event occurs when the state of a ValidationRule changes.

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

属性值

Boolean

如果在 Error 的状态更改时发生 ValidationRule 事件,则为 true;否则为 falsetrue if the Error event occurs when the state of a ValidationRule changes; otherwise, false. 默认值为 falseThe default is false.

示例

下面的示例创建一个 BindingGroup 并将设置 NotifyOnValidationError 为, true 以便应用程序可以 Validation.Error 在失败时处理事件 ValidationRuleThe following example creates a BindingGroup and sets NotifyOnValidationError to true so that the application can handle the Validation.Error event when a ValidationRule fails.

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

下面的示例处理 Validation.Error 事件。The following example handles the Validation.Error event.

// 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附加事件发生在具有的元素上 BindingGroupThe Validation.Error attached event occurs on the element that has the BindingGroup.

适用于