Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does AdornedElementPlaceholder exactly do when we use it in validation controlTemplate?

Tags:

wpf

xaml

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?

like image 856
Neha Avatar asked Jul 24 '14 08:07

Neha


2 Answers

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.

like image 125
Marcel B Avatar answered Nov 19 '22 18:11

Marcel B


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

like image 35
Pheonyx Avatar answered Nov 19 '22 16:11

Pheonyx