In This Article

VisualTreeHelperExtended Class

Contains static methods that are useful for performing common tasks with nodes in a visual tree.

public static class VisualTreeHelperExtended
Inheritance:
System.Object Object

Methods

GetAllDescendants(DependencyObject, Type)

Returns a list of System.Windows.DependencyObject values that includes all the descendant visual objects that are of the specified System.Type.

public static IList<DependencyObject> GetAllDescendants(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendants are returned.

desiredType System.Type

The desired descendants System.Type.

Returns

System.Collections.Generic.IList<System.Windows.DependencyObject>:

A list of System.Windows.DependencyObject values that includes all the descendant visual objects that are of the specified System.Type.

GetAllDescendants<T>(DependencyObject)

Returns a list of System.Windows.DependencyObject values that includes all the descendant visual objects that are of the specified System.Type.

public static IList<T> GetAllDescendants<T>(DependencyObject source)
    where T : DependencyObject
Type Parameters:
T -

The desired descendant System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendants are returned.

Returns

System.Collections.Generic.IList<T>:

A list of System.Windows.DependencyObject values that includes all the descendant visual objects that are of the specified System.Type.

GetAncestor(DependencyObject, Type)

Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

public static DependencyObject GetAncestor(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

desiredType System.Type

The desired ancestor System.Type.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

GetAncestor(DependencyObject, Type[])

Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is one of the specified System.Types.

public static DependencyObject GetAncestor(DependencyObject source, params Type[] desiredTypes)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

desiredTypes System.Type[]

The desired ancestor System.Types.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents an ancestor of the visual object that is one of the specified System.Types.

GetAncestor<T>(DependencyObject)

Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

public static T GetAncestor<T>(DependencyObject source)
    where T : DependencyObject
Type Parameters:
T -

The desired ancestor System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

Returns

T:

A System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

GetAncestor<T>(DependencyObject, Predicate<T>)

Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

public static T GetAncestor<T>(DependencyObject source, Predicate<T> condition)
    where T : DependencyObject
Type Parameters:
T -

The desired ancestor System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

condition System.Predicate<T>

The optional condition predicate to use for matching objects. Any object is matched if this is not passed.

Returns

T:

A System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified System.Type.

GetAncestorCount(DependencyObject, Type)

Returns the number of ancestors of the visual object that is of the specified System.Type.

public static int GetAncestorCount(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor count is returned.

desiredType System.Type

The desired ancestor System.Type.

Returns

System.Int32:

The number of ancestors of the visual object that is of the specified System.Type.

GetAncestorPopup(DependencyObject)

Returns a System.Windows.Controls.Primitives.Popup value that represents an ancestor of the visual object.

public static Popup GetAncestorPopup(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

Returns

System.Windows.Controls.Primitives.Popup:

A System.Windows.Controls.Primitives.Popup value that represents an ancestor of the visual object.

GetChild(DependencyObject, Type)

Returns a System.Windows.DependencyObject value that represents the first child visual object that is of the specified System.Type.

public static DependencyObject GetChild(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose child is returned.

desiredType System.Type

The desired child System.Type.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the first child visual object that is of the specified System.Type.

GetChild<T>(DependencyObject)

Returns a System.Windows.DependencyObject value that represents the first child visual object that is of the specified System.Type.

public static T GetChild<T>(DependencyObject source)
    where T : DependencyObject
Type Parameters:
T -

The desired child System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose child is returned.

Returns

T:

A System.Windows.DependencyObject value that represents the first child visual object that is of the specified System.Type.

GetCurrentOrAncestor(DependencyObject, Type)

Returns a System.Windows.DependencyObject value that represents the visual object, or an ancestor of the visual object, that is of the specified System.Type.

public static DependencyObject GetCurrentOrAncestor(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

desiredType System.Type

The desired ancestor System.Type.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the visual object, or an ancestor of the visual object, that is of the specified System.Type.

GetDescendant(DependencyObject, VisualTreeHelperExtended.VisualResultCallback)

Returns a System.Windows.DependencyObject which is a descendant of the specified object, using caller-defined VisualTreeHelperExtended.VisualResultCallback method.

public static DependencyObject GetDescendant(DependencyObject source, VisualTreeHelperExtended.VisualResultCallback resultCallback)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

resultCallback VisualTreeHelperExtended.VisualResultCallback

The result callback.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the descendant of the specified object that matches the user-defined criteria.

GetDescendant(DependencyObject, VisualTreeHelperExtended.VisualResultCallback, VisualTreeHelperExtended.VisualDescendantFilterCallback)

Returns a System.Windows.DependencyObject which is a descendant of the specified object, using caller-defined VisualTreeHelperExtended.VisualResultCallback and VisualTreeHelperExtended.VisualDescendantFilterCallback methods.

public static DependencyObject GetDescendant(DependencyObject source, VisualTreeHelperExtended.VisualResultCallback resultCallback, VisualTreeHelperExtended.VisualDescendantFilterCallback filterCallback)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

resultCallback VisualTreeHelperExtended.VisualResultCallback

The result callback.

filterCallback VisualTreeHelperExtended.VisualDescendantFilterCallback

The filter call back.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the descendant of the specified object that matches the user-defined criteria.

GetDescendant(DependencyObject, Type, Int32)

Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

public static DependencyObject GetDescendant(DependencyObject source, Type desiredType, int skipCount)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

desiredType System.Type

The desired descendant System.Type.

skipCount System.Int32

The number of items to skip before returning a match.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

GetDescendant<T>(DependencyObject, Int32)

Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

public static T GetDescendant<T>(DependencyObject source, int skipCount)
    where T : DependencyObject
Type Parameters:
T -

The desired descendant System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

skipCount System.Int32

The number of items to skip before returning a match.

Returns

T:

A System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

GetDescendant<T>(DependencyObject, Predicate<T>, Int32)

Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

public static T GetDescendant<T>(DependencyObject source, Predicate<T> condition, int skipCount)
    where T : DependencyObject
Type Parameters:
T -

The desired descendant System.Type.

Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

condition System.Predicate<T>

The optional condition predicate to use for matching objects. Any object is matched if this is not passed.

skipCount System.Int32

The number of items to skip before returning a match.

Returns

T:

A System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified System.Type, where 'n' is specified using a skip count.

GetFirstChild(DependencyObject)

Returns a System.Windows.DependencyObject value that represents the first child visual object.

public static DependencyObject GetFirstChild(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose child is returned.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the first child visual object.

GetFirstDescendant(DependencyObject, Type)

Returns a System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified System.Type.

public static DependencyObject GetFirstDescendant(DependencyObject source, Type desiredType)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

desiredType System.Type

The desired descendant System.Type.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified System.Type.

GetFirstDescendant(DependencyObject, Type, VisualTreeHelperExtended.VisualDescendantFilterCallback)

Returns a System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified System.Type, using the caller-defined VisualTreeHelperExtended.VisualDescendantFilterCallback method.

public static DependencyObject GetFirstDescendant(DependencyObject source, Type desiredType, VisualTreeHelperExtended.VisualDescendantFilterCallback filterCallback)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

desiredType System.Type

The desired descendant System.Type.

filterCallback VisualTreeHelperExtended.VisualDescendantFilterCallback

The filter call back.

Returns

System.Windows.DependencyObject:

A System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified System.Type.

GetFirstFocusableAncestor(DependencyObject)

Returns a System.Windows.UIElement value that represents the first ancestor visual object that is focusable.

public static UIElement GetFirstFocusableAncestor(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose ancestor is returned.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the first ancestor visual object that is focusable.

GetFirstFocusableDescendant(DependencyObject)

Returns a System.Windows.UIElement value that represents the first descendant visual object that is focusable.

public static UIElement GetFirstFocusableDescendant(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the first descendant visual object that is focusable.

GetFirstFocusableDescendant(DependencyObject, VisualTreeHelperExtended.VisualDescendantFilterCallback)

Returns a System.Windows.UIElement value that represents the first descendant visual object that is focusable, using the caller-defined VisualTreeHelperExtended.VisualDescendantFilterCallback method.

public static UIElement GetFirstFocusableDescendant(DependencyObject source, VisualTreeHelperExtended.VisualDescendantFilterCallback filterCallback)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

filterCallback VisualTreeHelperExtended.VisualDescendantFilterCallback

The filter call back.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the first descendant visual object that is focusable.

GetFirstTabStopDescendant(DependencyObject)

Returns a System.Windows.Controls.Control value that represents the first descendant visual object that is a tab stop.

public static Control GetFirstTabStopDescendant(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose descendant is returned.

Returns

System.Windows.Controls.Control:

A System.Windows.Controls.Control value that represents the first descendant visual object that is a tab stop.

Remarks

When a tab stop control is found, all siblings at the same level will be examined to locate and return the one with the lowest tab index.

GetItemsPanel(ItemsControl)

Returns a System.Windows.Controls.Panel value that represents the items panel of the specified System.Windows.Controls.ItemsControl.

public static Panel GetItemsPanel(ItemsControl source)
Parameter Type Description
source System.Windows.Controls.ItemsControl

The visual whose items panel is returned.

Returns

System.Windows.Controls.Panel:

A System.Windows.Controls.Panel value that represents the items panel.

GetNextFocusable(DependencyObject, DependencyObject)

Returns a System.Windows.UIElement value that represents the next visual object that is focusable.

public static UIElement GetNextFocusable(DependencyObject source, DependencyObject root)
Parameter Type Description
source System.Windows.DependencyObject

The visual used as a basis for the search.

root System.Windows.DependencyObject

The root visual used to limit the scope of the search.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the next visual object that is focusable.

GetNextFocusable(DependencyObject, DependencyObject, Boolean)

Returns a System.Windows.UIElement value that represents the next visual object that is focusable.

public static UIElement GetNextFocusable(DependencyObject source, DependencyObject root, bool examineSourceDescendants)
Parameter Type Description
source System.Windows.DependencyObject

The visual used as a basis for the search.

root System.Windows.DependencyObject

The root visual used to limit the scope of the search.

examineSourceDescendants System.Boolean

Whether the descendants of source may be examined.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the next visual object that is focusable.

GetPreviousFocusable(DependencyObject, DependencyObject)

Returns a System.Windows.UIElement value that represents the previous visual object that is focusable.

public static UIElement GetPreviousFocusable(DependencyObject source, DependencyObject root)
Parameter Type Description
source System.Windows.DependencyObject

The visual used as a basis for the search.

root System.Windows.DependencyObject

The root visual used to limit the scope of the search.

Returns

System.Windows.UIElement:

A System.Windows.UIElement value that represents the previous visual object that is focusable.

GetRoot(DependencyObject)

Returns the root System.Windows.DependencyObject in the visual tree.

public static DependencyObject GetRoot(DependencyObject source)
Parameter Type Description
source System.Windows.DependencyObject

The visual whose root is returned.

Returns

System.Windows.DependencyObject:

The root System.Windows.DependencyObject in the visual tree.

GetVisualParent(DependencyObject, Boolean)

Returns the visual parent of the specified source visual.

public static DependencyObject GetVisualParent(DependencyObject source, bool includeContentElements)
Parameter Type Description
source System.Windows.DependencyObject

The visual to examine.

includeContentElements System.Boolean

If the source is a ContentElement, whether to allow its logical parent to be returned.

Returns

System.Windows.DependencyObject:

The visual parent.

InvalidateMeasureForAllVisualsInSameTemplate(UIElement)

Invalidates measurement of all elements within the same source templated System.Windows.UIElement.

public static void InvalidateMeasureForAllVisualsInSameTemplate(UIElement sourceTemplatedElement)
Parameter Type Description
sourceTemplatedElement System.Windows.UIElement

The source templated System.Windows.UIElement.

InvalidateMeasureForVisualAncestorPath<PathEndType>(DependencyObject)

Invalidates measurement from the source visual up to an ancestor of type PathEndType.

public static void InvalidateMeasureForVisualAncestorPath<PathEndType>(DependencyObject source)
Type Parameters:
PathEndType -

The ancestor type at which to stop.

Parameter Type Description
source System.Windows.DependencyObject

The visual at which to start invalidation.

IsAtFocusEdgeWithin(UIElement, FocusNavigationDirection)

Tests if keyboard focus is currently positioned at a focus edge (i.e. first or last tab stop) within the given container.

public static bool IsAtFocusEdgeWithin(UIElement container, FocusNavigationDirection direction)
Parameter Type Description
container System.Windows.UIElement

The container to examine.

direction System.Windows.Input.FocusNavigationDirection

The direction of focus to be examined, either Previous or Next.

Returns

System.Boolean:

true if currently positioned at a focus edge; otherwise false.

Exceptions

Type Condition
System.NotSupportedException

Thrown when the focus direction is not supported.

IsDescendant(DependencyObject, DependencyObject)

Returns whether the specified source System.Windows.DependencyObject is a descendant of the possible ancestor System.Windows.DependencyObject.

public static bool IsDescendant(DependencyObject possibleAncestor, DependencyObject source)
Parameter Type Description
possibleAncestor System.Windows.DependencyObject

The possible ancestor.

source System.Windows.DependencyObject

The initial object to examine.

Returns

System.Boolean:

true if the source System.Windows.DependencyObject is a descendant of the possible ancestor System.Windows.DependencyObject; otherwise, false.

IsFocusable(UIElement)

Returns whether the specified System.Windows.UIElement is focusable.

public static bool IsFocusable(UIElement element)
Parameter Type Description
element System.Windows.UIElement

The System.Windows.UIElement to examine.

Returns

System.Boolean:

true if the specified System.Windows.UIElement is focusable; otherwise, false.

IsInMainFocusScope()

Returns whether the element currently with keyboard focus is in the main focus scope.

public static bool IsInMainFocusScope()

Returns

System.Boolean:

true if the element currently with keyboard focus is in the main focus scope; otherwise, false.

IsInMainFocusScope(DependencyObject)

Returns whether the specified element is in the main focus scope.

public static bool IsInMainFocusScope(DependencyObject element)
Parameter Type Description
element System.Windows.DependencyObject

The element to examine.

Returns

System.Boolean:

true if the specified element is in the main focus scope; otherwise, false.

IsMouseOver(DependencyObject, DragEventArgs)

Returns whether the bounds of the specified System.Windows.DependencyObject contains the mouse without using a call to IsMouseOver, which can provide inaccurate results in mouse capture scenarios.

public static bool IsMouseOver(DependencyObject obj, DragEventArgs e)
Parameter Type Description
obj System.Windows.DependencyObject

UIElement instance to be tested.

e System.Windows.DragEventArgs

A System.Windows.DragEventArgs that can be used to determine mouse position.

Returns

System.Boolean:

true if the bounds of the element contain the mouse position; otherwise, false.

Remarks

The specified object must be a System.Windows.UIElement.

IsMouseOver(DependencyObject, MouseEventArgs)

Returns whether the bounds of the specified System.Windows.DependencyObject contains the mouse without using a call to IsMouseOver, which can provide inaccurate results in mouse capture scenarios.

public static bool IsMouseOver(DependencyObject obj, MouseEventArgs e)
Parameter Type Description
obj System.Windows.DependencyObject

UIElement instance to be tested.

e System.Windows.Input.MouseEventArgs

A System.Windows.Input.MouseEventArgs that can be used to determine mouse position.

Returns

System.Boolean:

true if the bounds of the element contain the mouse position; otherwise, false.

Remarks

The specified object must be a System.Windows.UIElement.

IsSameOrDescendant(DependencyObject, DependencyObject)

Returns whether the specified source System.Windows.DependencyObject is the same as or a descendant of the possible ancestor System.Windows.DependencyObject.

public static bool IsSameOrDescendant(DependencyObject possibleAncestor, DependencyObject source)
Parameter Type Description
possibleAncestor System.Windows.DependencyObject

The possible ancestor.

source System.Windows.DependencyObject

The initial object to examine.

Returns

System.Boolean:

true if the source System.Windows.DependencyObject is the same as or a descendant of the possible ancestor System.Windows.DependencyObject; otherwise, false.

IsVisual(DependencyObject)

Returns whether the specified System.Windows.DependencyObject is a System.Windows.Media.Visual or Visual3D.

public static bool IsVisual(DependencyObject obj)
Parameter Type Description
obj System.Windows.DependencyObject

The System.Windows.DependencyObject to examine.

Returns

System.Boolean:

true if the specified System.Windows.DependencyObject is a System.Windows.Media.Visual or Visual3D; otherwise, false.

Inherited Members

  • System.Object.ToString()
  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object, System.Object)
  • System.Object.ReferenceEquals(System.Object, System.Object)
  • System.Object.GetHashCode()
  • System.Object.GetType()
  • System.Object.MemberwiseClone()