An adorner is a special-purpose custom element whose purpose is to add visual features to a UI element. An adorner appears at the same position as the element it adorns, but it will be at top of the Z order—it appears above all nonadorner elements in the window. Adorners are typically used in interactive editing scenarios to display selection outlines or handles. Figure 18-2 shows a typical example from Microsoft Expression Blend.

Adorners in action

Figure 18-2. Adorners in action

Figure 18-2 shows two rounded rectangles. The one with the white fill is on top of the gray one, partially obscuring it. The gray one underneath has been selected, causing various handles, shapes, and labels to light up. For example, there's a rectangle showing the bounding box, with small, square resize handles at each corner, and there's an outline version of the shape itself. Notice that the white rectangle has obscured none of these features. Even though the gray rectangle is beneath the white rectangle, all of the handles appear on top, making it easy to edit the shape even though it is mostly obscured. These handles and other features appear on top because they use WPF's adorner system.

Adorners are able to appear on top because WPF creates a special AdornerLayer element at the top of the Z order. There is nothing magic about this—you could achieve the same effect without using the adorner infrastructure ...

Get Programming WPF, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.