Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdornerDecorator - what does it matter where they are placed?

Tags:

wpf

With some xaml like this:

<Grid Name="grid">
        <AdornerDecorator>
        <TextBox Height="23" HorizontalAlignment="Left" Name="textBox1" Width="120" />
        </AdornerDecorator>
</Grid>

The WPF Snoop utility indicates textBox1 is a child of AdornerDecorator (as you would expect) but also that the AdornerLayer that AdornerDecorator creates is also a child. As a custom adorner added to the AdornerLayer can be displayed 'outside' the textbox, the AdornerLayer's drawing surface must stretch outside too (presumably all over the window).

So, what real significance does the placement of AdornerDecorator have (given we bind a UI element to the custom adorner, which we place in the AdornerLayer)? I know AdornerLayer.GetAdorner(textBox1) will get the first adorner layer in the visual tree up from textbox1, but what does it matter where that is (as the custom ardorner gets added to the layer and the custom ardoner knows which element it is bound to)?

like image 537
sturdytree Avatar asked Mar 13 '12 21:03

sturdytree


1 Answers

The short answer is that it matters when you start to deal with controls that overlap other controls (in the z-index plane) and you care about whether or not a particular adorner layer shows on top of the overlapping controls. For example, when you use an ErrorTemplate, its contents get rendered in an adorner layer and if you don't supply an <AdornerDecorator> in your app (meaning that you just use the one provided by most Window templates), then you can end up with this happening.

By placing the <AdornerDecorator> where we want, we can control how this overlapping behaves.

like image 190
Jason Frank Avatar answered Nov 16 '22 00:11

Jason Frank