通过


Validation.ValidationAdornerSiteFor 附加属性

定义

获取或设置显示此元素以指示发生错误的元素。

see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor
see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor
see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor

示例

以下示例使用一个 Label 作为装饰器站点,用于在项 ItemsControl上发生的验证错误。 该示例设置 Validation.ValidationAdornerSite 标签中 ItemContainerStyle 每个项容器的对应项。 该示例使用该Validation.ValidationAdornerSiteFor属性获取具有错误的项容器,并将报告的第一个项容器绑定ContentLabel在一起ValidationError

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

注解

Validation.ValidationAdornerSite Validation.ValidationAdornerSiteFor附加属性相互引用,你可以设置任一属性。 例如,假设 Label 显示绑定 TextBox数据上的验证错误。 可以执行以下操作之一来建立该关系:

设置其中一个属性时,另一个属性设置为设置附加属性的元素;无论你选择的哪一个选项,其Validation.ValidationAdornerSiteTextBoxLabelValidationAdornerSiteFor,而对于Label是 。TextBox

Dependency 属性信息

物品 价值
标识符字段 ValidationAdornerSiteForProperty
元数据属性设置为 true 没有

适用于