ValidationRule.ValidatesOnTargetUpdated Property


Gets or sets a value that indicates whether the validation rule runs when the target of the Binding is updated.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public Property ValidatesOnTargetUpdated As Boolean

Property Value

Type: System.Boolean

true if the validation rule runs when the target of the Binding is updated; otherwise, false.

The following example checks whether the TextBox is empty. 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"
    <Binding Source="{StaticResource myObject}"
        <src:ValueIsNotNull ValidatesOnTargetUpdated="True" />

The following example shows the ValidationRule that is used in the previous example and the event handler for the Error event.

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
            Return New ValidationResult(False, "Value must not be null")
        End If
    End Function
End Class

.NET Framework
Available since 3.0
Return to top