ValidationRule.ValidatesOnTargetUpdated ValidationRule.ValidatesOnTargetUpdated ValidationRule.ValidatesOnTargetUpdated ValidationRule.ValidatesOnTargetUpdated Property

Definición

Obtiene o establece un valor que indica si la regla de validación se ejecuta cuando se actualiza el destino de Binding.Gets or sets a value that indicates whether the validation rule runs when the target of the Binding is updated.

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

Valor de propiedad

Es true si la regla de validación se ejecuta cuando se actualiza el destino de Binding; de lo contrario, es false.true if the validation rule runs when the target of the Binding is updated; otherwise, false.

Ejemplos

El ejemplo siguiente se comprueba si el TextBox está vacío.The following example checks whether the TextBox is empty. El ValidationRule, ValueIsNotNull, tiene ValidatesOnTargetUpdated establecido en true, de modo que cuando se inicia la aplicación, el ValidationRule se ejecuta y muestra un mensaje si la TextBox está vacío.The ValidationRule, ValueIsNotNull, has ValidatesOnTargetUpdated set to true, so that when the application starts, the ValidationRule runs and displays a message if the TextBox is empty.

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

El ejemplo siguiente se muestra el ValidationRule que se utiliza en el ejemplo anterior y el controlador de eventos para el Error eventos.The following example shows the ValidationRule that is used in the previous example and the event handler for the Error event.

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

Se aplica a