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)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
Public Property ValidatesOnTargetUpdated As Boolean
<object ValidatesOnTargetUpdated="bool" .../>

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


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


.NET Framework

Supported in: 4, 3.5 SP1, 3.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft