* net-current-v30plus-md.md * net-current-v40plus-md.md * tla2sharptla-ui-md.md * tla2sharptla-uiautomation-md.md * tla2sharptla-winclient-md.md * tla2sharptla-xaml-md.md * tlasharptla-ui-md.md * tlasharptla-uiautomation-md.md * tlasharptla-winclient-md.md * tlasharptla-xaml-md.md * fix warnings
1.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|
| How to: Bind an Adorner to an Element | 03/30/2017 |
|
|
b2101611-a0ee-4137-bdb8-9b3673d2e6b9 |
How to: Bind an Adorner to an Element
This example shows how to programmatically bind an adorner to a specified xref:System.Windows.UIElement.
Example
To bind an adorner to a particular xref:System.Windows.UIElement, follow these steps:
-
Call the
staticmethod xref:System.Windows.Documents.AdornerLayer.GetAdornerLayer%2A to get an xref:System.Windows.Documents.AdornerLayer object for the xref:System.Windows.UIElement to be adorned. xref:System.Windows.Documents.AdornerLayer.GetAdornerLayer%2A 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 xref:System.Windows.Documents.AdornerLayer.Add%2A method to bind the adorner to the target UIElement.
The following example binds a SimpleCircleAdorner (shown above) to a xref:System.Windows.Controls.TextBox named myTextBox.
[!code-csharpAdorners_SimpleCircleAdorner#_AdornSingleElement] [!code-vbAdorners_SimpleCircleAdorner#_AdornSingleElement]
Note
Using Extensible Application Markup Language (XAML) to bind an adorner to another element is currently not supported.