* Metadata updates for US-1889327. * H2 edits. * Updated column header. * Minor edits. * Review edits.
2.1 KiB
title, ms.date, ms.custom, description, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | ms.custom | description | dev_langs | helpviewer_keywords | ms.assetid | |||
|---|---|---|---|---|---|---|---|---|---|
| How to: Remove an Adorner from an Element | 03/30/2017 | devdivchpfy22 | Learn how to remove an Adorner from an Element. |
|
|
97cf4d9f-0596-429e-8526-32a30aa4ae99 |
How to: Remove an Adorner from an Element
This example shows how to programmatically remove a specific adorner from a specified xref:System.Windows.UIElement.
Retrieve an adorner on a UIElement
This verbose code example removes the first adorner in the array of adorners returned by xref:System.Windows.Documents.AdornerLayer.GetAdorners%2A. This example happens to retrieve the adorners on a xref:System.Windows.UIElement named myTextBox. If the element specified in the call to xref:System.Windows.Documents.AdornerLayer.GetAdorners%2A has no adorners, null is returned. This code explicitly checks for a null array, and is best suited for applications where a null array is expected to be relatively common.
[!code-csharpAdornersMiscCode#_RemoveSpecificAdornerLong] [!code-vbAdornersMiscCode#_RemoveSpecificAdornerLong]
Example
This condensed code example is functionally equivalent to the verbose example shown above. This code does not explicitly check for a null array, so it is possible that a xref:System.NullReferenceException exception may be raised. This code is best suited for applications where a null array is expected to be rare.
[!code-csharpAdornersMiscCode#_RemoveSpecificAdornerShort] [!code-vbAdornersMiscCode#_RemoveSpecificAdornerShort]