This topic has not yet been rated - Rate this topic

AdornerLayer.GetAdorners Method

Returns an array of adorners that are bound to the specified UIElement.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
public Adorner[] GetAdorners(
	UIElement element
)

Parameters

element
Type: System.Windows.UIElement
The UIElement to retrieve an array of adorners for.

Return Value

Type: System.Windows.Documents.Adorner[]
An array of adorners that decorate the specified UIElement, or null if there are no adorners bound to the specified element.

This example shows how to programmatically remove a specific adorner from a specified UIElement.

This verbose code example removes the first adorner in the array of adorners returned by GetAdorners. This example happens to retrieve the adorners on a UIElement named myTextBox. If the element specified in the call to GetAdorners 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.


Adorner[] toRemoveArray = myAdornerLayer.GetAdorners(myTextBox);
Adorner toRemove;
if (toRemoveArray != null)
{
  toRemove = toRemoveArray[0];
  myAdornerLayer.Remove(toRemove);
}


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 NullReferenceException exception may be raised. This code is best suited for applications where a null array is expected to be rare.


try { myAdornerLayer.Remove((myAdornerLayer.GetAdorners(myTextBox))[0]); } catch { }


More Code

How to: Remove all Adorners from an ElementThis example shows how to programmatically remove all adorners from a specified UIElement.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.