What exactly are the differences between AdornerLayer.Update() and AdornerLayer.Update(UIElement)?
As far as I understand it, there is exactly one adorner layer per ui element, which you can get with AdornerLayer.GetAdornerLayer(Visual). The only difference I can see is if there isn't a adorner layer for each ui element. So for example if I have the following visual tree:
UIElement1
-> UIElement2
-> UIElement3
Then somehow UIElement2
and 3
don't have their own adorner layer but use the adorner layer of UIElement1
. And then Update()
would update all adorners for UIElement1
, 2
and 3
and Update(UIElement)
would only update the adorners for the corresponding ui element.
So what are the conditions for when a UI element has its own adorner layer and when it uses the adorner layer of a UI element higher up in the visual tree?
Each UIElement
does not automatically have its own, unique AdornerLayer
. Take a look at this documentation:
Adorners Overview - Adorning a Single UIElement
GetAdornerLayer walks up the visual tree, starting at the specified UIElement, and returns the first adorner layer it finds. (If no adorner layers are found, the method returns
null
.)
The AdornerDecorator specifies the position of the AdornerLayer in the visual tree. It is typically used in a ControlTemplate for a control that might host Adorner objects. For example, the ControlTemplate of a Window contains an AdornerDecorator so that the child elements of the window can be adorned. The GetAdornerLayer method returns
null
if you pass in an element that does not have an AdornerDecorator as an ancestor in its visual tree.
So, if you use a Window
as the root element, there is guaranteed to be at least one Adorner
in the visual tree, there may be more depending on what other elements you use.