Validation::ValidationAdornerSiteFor Attached Property

Gets or sets the element for which this element appears to indicate that an error occurred.

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

See GetValidationAdornerSiteFor, SetValidationAdornerSiteFor
<object Validation.ValidationAdornerSiteFor="DependencyObject" .../>

Property Value

Type: System.Windows::DependencyObject
The element for which this element appears to indicate that an error occurred.

Identifier field

ValidationAdornerSiteForProperty

Metadata properties set to true

None

The Validation::ValidationAdornerSite and Validation::ValidationAdornerSiteFor attached properties reference each other, and you can set either one. For example, suppose that a Label displays validation errors that occur on a data bound TextBox. You can do one of the following to establish that relationship:

When you set one of the properties, the other property is set to the element on which you set the attached property; regardless of which of the previous options you choose, the Validation::ValidationAdornerSite for the TextBox is the Label and the ValidationAdornerSiteFor for the Label is the TextBox.

The following example uses a Label as the adorner site for the validation errors that occur on items in an ItemsControl. The example sets the Validation::ValidationAdornerSite for each item container in the ItemContainerStyle to the label. The example uses the Validation::ValidationAdornerSiteFor property to get the item container that has the error and binds the Content of the Label to the first ValidationError that is reported.

<ItemsControl Name="customerList"  ItemTemplate="{StaticResource ItemTemplate}"
              ItemsSource="{Binding}">
  <ItemsControl.ItemBindingGroup>
    <BindingGroup>
      <BindingGroup.ValidationRules>
        <src:AreasMatch/>
      </BindingGroup.ValidationRules>
    </BindingGroup>
  </ItemsControl.ItemBindingGroup>
  <ItemsControl.ItemContainerStyle>
    <Style TargetType="{x:Type ContentPresenter}">
      <Setter Property="Validation.ValidationAdornerSite"
              Value="{Binding ElementName=validationErrorReport}"/>
    </Style>
  </ItemsControl.ItemContainerStyle>
</ItemsControl>


...


<Label Name="validationErrorReport" 
       Content="{Binding RelativeSource={RelativeSource Self}, 
       Path=(Validation.ValidationAdornerSiteFor).(Validation.Errors)[0].ErrorContent}"
       Margin="5" Foreground="Red" HorizontalAlignment="Center"/>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft