Show / Hide Table of Contents

Class VisualTreeExtensions

Provides useful extensions for working with the visual tree.

Inheritance
System.Object
VisualTreeExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: System.Windows.Controls.Primitives
Assembly: OpenSilver.Controls.Toolkit.dll
Syntax
public static class VisualTreeExtensions
Remarks

Since many of these extension methods are declared on types like DependencyObject high up in the class hierarchy, we've placed them in the Primitives namespace which is less likely to be imported for normal scenarios.

Methods

| Improve this Doc View Source

GetBoundsRelativeTo(FrameworkElement, UIElement)

Get the bounds of an element relative to another element.

Declaration
public static Rect? GetBoundsRelativeTo(this FrameworkElement element, UIElement otherElement)
Parameters
Type Name Description
FrameworkElement element

The element.

UIElement otherElement

The element relative to the other element.

Returns
Type Description
System.Nullable<Rect>

The bounds of the element relative to another element, or null if the elements are not related.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

System.ArgumentNullException

otherElement is null.

| Improve this Doc View Source

GetVisualAncestors(DependencyObject)

Get the visual tree ancestors of an element.

Declaration
public static IEnumerable<DependencyObject> GetVisualAncestors(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree ancestors of the element.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualAncestorsAndSelf(DependencyObject)

Get the visual tree ancestors of an element and the element itself.

Declaration
public static IEnumerable<DependencyObject> GetVisualAncestorsAndSelf(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree ancestors of an element and the element itself.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualChildren(DependencyObject)

Get the visual tree children of an element.

Declaration
public static IEnumerable<DependencyObject> GetVisualChildren(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree children of an element.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualChildrenAndSelf(DependencyObject)

Get the visual tree children of an element and the element itself.

Declaration
public static IEnumerable<DependencyObject> GetVisualChildrenAndSelf(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree children of an element and the element itself.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualDescendants(DependencyObject)

Get the visual tree descendants of an element.

Declaration
public static IEnumerable<DependencyObject> GetVisualDescendants(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree descendants of an element.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualDescendantsAndSelf(DependencyObject)

Get the visual tree descendants of an element and the element itself.

Declaration
public static IEnumerable<DependencyObject> GetVisualDescendantsAndSelf(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree descendants of an element and the element itself.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualSiblings(DependencyObject)

Get the visual tree siblings of an element.

Declaration
public static IEnumerable<DependencyObject> GetVisualSiblings(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree siblings of an element.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

GetVisualSiblingsAndSelf(DependencyObject)

Get the visual tree siblings of an element and the element itself.

Declaration
public static IEnumerable<DependencyObject> GetVisualSiblingsAndSelf(this DependencyObject element)
Parameters
Type Name Description
DependencyObject element

The element.

Returns
Type Description
System.Collections.Generic.IEnumerable<DependencyObject>

The visual tree siblings of an element and the element itself.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

| Improve this Doc View Source

InvokeOnLayoutUpdated(FrameworkElement, Action)

Perform an action when the element's LayoutUpdated event fires.

Declaration
public static void InvokeOnLayoutUpdated(this FrameworkElement element, Action action)
Parameters
Type Name Description
FrameworkElement element

The element.

System.Action action

The action to perform.

Exceptions
Type Condition
System.ArgumentNullException

element is null.

System.ArgumentNullException

action is null.

  • Improve this Doc
  • View Source