Modifier

Partager via


Validation.ValidationAdornerSite Attached Property

Definition

Gets or sets the element that appears to indicate that a validation error occurred on the bound element where this property is set.

see GetValidationAdornerSite, and SetValidationAdornerSite
see GetValidationAdornerSite, and SetValidationAdornerSite
see GetValidationAdornerSite, and SetValidationAdornerSite

Examples

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

Remarks

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:

Dependency Property Information

Item Value
Identifier field ValidationAdornerSiteProperty
Metadata properties set to true None

Applies to