Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WPF

How to Bind an Adorner to an Element?

1.00/5 (1 vote)
13 Nov 2010CPOL 14.4K  
Binding an Adorner to an Element
To bind an adorner to a particular UIElement, follow the below mentioned steps.

Call the static method GetAdornerLayer to get an AdornerLayer of object for the UIElement to be adorned. 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).

Call the Add method to bind the adorner to the target UIElement.
The following example binds a SimpleCircleAdorner (shown above) to a TextBox named myTextBox.

C#
C#
myAdornerLayer = AdornerLayer.GetAdornerLayer(myTextBox);
myAdornerLayer.Add(new SimpleCircleAdorner(myTextBox));


Have fun with WPF programming. Enjoy......!

Note:Using Extensible Application Markup Language (XAML) to bind an adorner to another element is currently not supported.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)