Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-bind-an-adorner-to-an-element.md
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* 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
2022-03-16 12:14:11 -04:00

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
csharp
vb
UIElements [WPF], binding adorners to
adorners [WPF], binding to specified UIElements
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:

  1. Call the static method 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.)

  2. 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.

See also