Validation.ValidationAdornerSiteFor Attached Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the element for which this element appears to indicate that an error occurred.
see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor
see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor
see GetValidationAdornerSiteFor, and SetValidationAdornerSiteFor
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:
Set Validation.ValidationAdornerSite for the TextBox to the Label.
Set Validation.ValidationAdornerSiteFor for the Label to the TextBox.
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.
Dependency Property Information
Identifier field | ValidationAdornerSiteForProperty |
Metadata properties set to true |
None |
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기