ValidationRule.ValidatesOnTargetUpdated Eigenschaft

Definition

Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob die Gültigkeitsprüfungsregel ausgeführt wird, wenn das Ziel der Binding Aktualisierung erfolgt.

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

Eigenschaftswert

truewenn die Gültigkeitsprüfungsregel ausgeführt wird, wenn das Ziel der Binding Aktualisierung aktualisiert wird; andernfalls . false

Beispiele

Im folgenden Beispiel wird überprüft, ob die Datei TextBox leer ist. Der ValidationRule, ValueIsNotNullhat ValidatesOnTargetUpdated auf true, so festgelegt, dass beim Starten der Anwendung die ValidationRule Ausführung und zeigt eine Meldung an, wenn die TextBox Leer ist.

<TextBox Width="150"
         Validation.Error="ItemError">
  <TextBox.Text>
    <Binding Source="{StaticResource myObject}"
             Path="PropertyB"
             UpdateSourceTrigger="PropertyChanged"
             NotifyOnValidationError="True">
      <Binding.ValidationRules>
        <src:ValueIsNotNull ValidatesOnTargetUpdated="True" />
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>

Im folgenden Beispiel wird das ValidationRule im vorherigen Beispiel und der Ereignishandler für das Error Ereignis verwendet.

public class ValueIsNotNull : ValidationRule
{
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        string str = value as string;

        if (!string.IsNullOrEmpty(str))
        {
            return ValidationResult.ValidResult;
        }
        else
        {
            return new ValidationResult(false, "Value must not be null");
        }
    }
}
Public Class ValueIsNotNull
    Inherits ValidationRule
    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As ValidationResult
        Dim str As String = TryCast(value, String)

        If Not String.IsNullOrEmpty(str) Then
            Return ValidationResult.ValidResult
        Else
            Return New ValidationResult(False, "Value must not be null")
        End If
    End Function
End Class

Gilt für: