Creating adorners
Adorners are elements that exist in a distinct adorner layer, not part of the normal visual tree. All adorners in a particular layer always sit on top (higher Z index) of the element they adorn. This characteristic of adorners makes them an excellent choice for things such as selection handles, popup elements, and other special tasks where bothering with the normal visual tree is impossible or complicated at best.
In this recipe, we'll take a look at creating and using adorners to indicate selection.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create an application that draws a bunch of circles that can be dragged with the mouse. The currently selected circle will be marked with an adorner.
Create a new WPF application named
CH09.AdornerDemo
.Open
MainWindow.xaml
. Replace the existingGrid
with aCanvas
as follows:<Canvas x:Name="_canvas" Background="White"> </Canvas>
Open
MainWindow.xaml.cs
. We want to create a bunch of random circles...