* 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 all Adorners from an Element | 03/30/2017 | devdivchpfy22 | Learn how to remove all Adorners from an Element. |
|
|
fe5303a3-b76e-4643-aafb-51419032b47b |
How to: Remove all Adorners from an Element
This example shows how to programmatically remove all adorners from a specified xref:System.Windows.UIElement.
Retrieve the adorners on a UIElement
This verbose code example removes all of the adorners 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#_RemoveAllAdornersLong] [!code-vbAdornersMiscCode#_RemoveAllAdornersLong]
Code 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#_RemoveAllAdornersShort] [!code-vbAdornersMiscCode#_RemoveAllAdornersShort]