问题
After going through several articles and examples showing usage of
AdornedElementPlaceholder
i am still confused that what is the exact functionality it incorporates to xaml validation?
回答1:
If you use Validations you need to show the user where (and what) failed to validated and that’s where AdornedElementPlaceholder
comes into play. It is a Placeholder that has exactly the same size of the UIElement you’re validating.
Let’s say you’re validating user input on a TextBox
and want to show a red box around the TextBox
when the validation fails. Define a ValidationRule and a validation template for the TextBox
. If the ValidationRule fails, then the Validation.ErrorTemplate
is shown on your TextBox
. Inside the template the AdornedElementPlaceholder
tells the Framework where to place your template on the UI. In our case the template might look like this:
<ControlTemplate>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder />
</Border>
</ControlTemplate>
You should read this article.
回答2:
I believe the AdornedElementPlaceholder is used to show where the "validation indicator element" is positioned in relation to the control being validated. I.e. if you have a text box and when validation fails a red x appears on the right of the box, I believe (although not 100%) that the AdornedElementPlaceholder is responsible for that positioning.
Represents the element used in a ControlTemplate to specify where a decorated control is placed relative to other elements in the ControlTemplate.
Source: http://msdn.microsoft.com/en-us/library/system.windows.controls.adornedelementplaceholder(v=vs.110).aspx
来源:https://stackoverflow.com/questions/24928832/what-does-adornedelementplaceholder-exactly-do-when-we-use-it-in-validation-cont