Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Validation Class

Provides methods and attached properties that support data validation and govern the visual state of the control.


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

public static class Validation

The Validation type exposes the following members.

Public attached propertySupported by Silverlight for Windows PhoneErrorsGets a collection of ValidationError objects associated with the binding target element.
Public attached propertySupported by Silverlight for Windows PhoneHasErrorGets a value that indicates whether any binding on the target element has a validation error.

Public methodStatic memberSupported by Silverlight for Windows PhoneGetErrorsGets the value of the Errors attached property for the specified element.
Public methodStatic memberSupported by Silverlight for Windows PhoneGetHasErrorGets the value of the HasError attached property for the specified element.

Public fieldStatic memberSupported by Silverlight for Windows PhoneErrorsPropertyIdentifies the Errors attached property.
Public fieldStatic memberSupported by Silverlight for Windows PhoneHasErrorPropertyIdentifies the HasError attached property.

The Validation class provides support for displaying validation error information by using a control template. For more information about control templates, see Control Customization.

The following code example demonstrates how to use the Validation class in a control template. This template is used as a static resource by several default control templates to display a validation error message in a tool tip. For a complete control template example, see TextBox Styles and Templates.

<ControlTemplate x:Key="ValidationToolTipTemplate">
      <Grid x:Name="Root" Margin="5,0" RenderTransformOrigin="0,0" Opacity="0">
              <TranslateTransform x:Name="xform" X="-25"/>
              <vsm:VisualStateGroup Name="OpenStates">
                      <vsm:VisualTransition GeneratedDuration="0"/>
                      <vsm:VisualTransition To="Open" GeneratedDuration="0:0:0.2">
                              <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0:0:0.2">
                                      <BackEase Amplitude=".3" EasingMode="EaseOut"/>
                              <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2"/>
                  <vsm:VisualState x:Name="Closed">
                          <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
                  <vsm:VisualState x:Name="Open">
                          <DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0"/>
                          <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>

          <Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5"/>
          <Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4"/>
          <Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3"/>
          <Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2"/>

          <Border Background="#FFDC000C" CornerRadius="2"/>
          <Border CornerRadius="2">
                  Foreground="White" Margin="8,4,8,4" MaxWidth="250" TextWrapping="Wrap" Text="{Binding (Validation.Errors)[0].ErrorContent}"/>


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2017 Microsoft