VisualTreeHelperExtended Class
Contains static methods that are useful for performing common tasks with nodes in a visual tree.
public static class VisualTreeHelperExtended
- Inheritance:
- 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 Type.
[Browsable(false)]
[Obsolete("Use the generic GetAllDescendants<T> method instead.")]
public static IList<DependencyObject> GetAllDescendants(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendants are returned. |
| desiredType | Type | The desired descendants Type. |
Returns
- IList<DependencyObject>
GetAllDescendants<T>(DependencyObject)
Returns a list of System.Windows.DependencyObject values that includes all the descendant visual objects that are of the specified Type.
public static IList<T> GetAllDescendants<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired descendant Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendants are returned. |
Returns
- IList<T>
GetAncestor(DependencyObject, Type)
Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified Type.
[Browsable(false)]
[Obsolete("Use the generic GetAncestor<T> method instead.")]
public static DependencyObject? GetAncestor(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
| desiredType | Type | The desired ancestor Type. |
Returns
- DependencyObject
GetAncestor(DependencyObject, params Type[])
Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is one of the specified Types.
public static DependencyObject? GetAncestor(DependencyObject source, params Type[] desiredTypes)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
| desiredTypes | Type[] | The desired ancestor Types. |
Returns
- DependencyObject
GetAncestorCount(DependencyObject, Type)
Returns the number of ancestors of the visual object that is of the specified Type.
[Browsable(false)]
[Obsolete("Use the generic GetAncestorCount<T> method instead.")]
public static int GetAncestorCount(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor count is returned. |
| desiredType | Type | The desired ancestor Type. |
Returns
GetAncestorCount<T>(DependencyObject)
Returns the number of ancestors of the visual object that is of the specified Type.
public static int GetAncestorCount<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired ancestor Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor count is returned. |
Returns
GetAncestorPopup(DependencyObject?)
Returns a Popup value that represents an ancestor of the visual object.
public static Popup? GetAncestorPopup(DependencyObject? source)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
Returns
GetAncestor<T>(DependencyObject)
Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified Type.
public static T? GetAncestor<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired ancestor Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
Returns
- T
GetAncestor<T>(DependencyObject, Predicate<T>?)
Returns a System.Windows.DependencyObject value that represents an ancestor of the visual object that is of the specified Type.
public static T? GetAncestor<T>(DependencyObject source, Predicate<T>? condition) where T : class
- Type Parameters:
-
T-The desired ancestor Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
| condition | Predicate<T> | The optional condition predicate to use for matching objects. Any object is matched if this is not passed. |
Returns
- T
GetChild(DependencyObject, Type)
Returns a System.Windows.DependencyObject value that represents the first child visual object that is of the specified Type.
[Browsable(false)]
[Obsolete("Use the generic GetChild<T> method instead.")]
public static DependencyObject? GetChild(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose child is returned. |
| desiredType | Type | The desired child Type. |
Returns
- DependencyObject
GetChild<T>(DependencyObject)
Returns a System.Windows.DependencyObject value that represents the first child visual object that is of the specified Type.
public static T? GetChild<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired child Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose child is returned. |
Returns
- T
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 Type.
[Browsable(false)]
[Obsolete("Use the generic GetCurrentOrAncestor<T> method instead.")]
public static DependencyObject? GetCurrentOrAncestor(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
| desiredType | Type | The desired ancestor Type. |
Returns
- DependencyObject
GetCurrentOrAncestor<T>(DependencyObject)
Returns a System.Windows.DependencyObject value that represents the visual object, or an ancestor of the visual object, that is of the specified Type.
public static T? GetCurrentOrAncestor<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired ancestor Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
Returns
- T
GetDescendant(DependencyObject, 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 | DependencyObject | The visual whose descendant is returned. |
| resultCallback | VisualTreeHelperExtended.VisualResultCallback | The result callback. |
Returns
- DependencyObject
GetDescendant(DependencyObject, VisualResultCallback, 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 | DependencyObject | The visual whose descendant is returned. |
| resultCallback | VisualTreeHelperExtended.VisualResultCallback | The result callback. |
| filterCallback | VisualTreeHelperExtended.VisualDescendantFilterCallback | The filter call back. |
Returns
- DependencyObject:
A System.Windows.DependencyObject value that represents the descendant of the specified object that matches the user-defined criteria.
GetDescendant(DependencyObject, Type, int)
Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified Type, where 'n' is specified using a skip count.
[Browsable(false)]
[Obsolete("Use the generic GetDescendant<T> method instead.")]
public static DependencyObject? GetDescendant(DependencyObject source, Type desiredType, int skipCount)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
| desiredType | Type | The desired descendant Type. |
| skipCount | int | The number of items to skip before returning a match. |
Returns
- DependencyObject
GetDescendant<T>(DependencyObject, int)
Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified Type, where 'n' is specified using a skip count.
public static T? GetDescendant<T>(DependencyObject source, int skipCount) where T : class
- Type Parameters:
-
T-The desired descendant Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
| skipCount | int | The number of items to skip before returning a match. |
Returns
- T
GetDescendant<T>(DependencyObject, Predicate<T>?, int)
Returns a System.Windows.DependencyObject value that represents the n-th descendant visual object that is of the specified Type, where 'n' is specified using a skip count.
public static T? GetDescendant<T>(DependencyObject source, Predicate<T>? condition, int skipCount) where T : class
- Type Parameters:
-
T-The desired descendant Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
| condition | Predicate<T> | The optional condition predicate to use for matching objects. Any object is matched if this is not passed. |
| skipCount | int | The number of items to skip before returning a match. |
Returns
- T
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 | DependencyObject | The visual whose child is returned. |
Returns
- DependencyObject
GetFirstDescendant(DependencyObject, Type)
Returns a System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified Type.
[Browsable(false)]
[Obsolete("Use the generic GetFirstDescendant<T> method instead.")]
public static DependencyObject? GetFirstDescendant(DependencyObject source, Type desiredType)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
| desiredType | Type | The desired descendant Type. |
Returns
- DependencyObject
GetFirstDescendant(DependencyObject, Type, VisualDescendantFilterCallback?)
Returns a System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified Type, using the caller-defined VisualTreeHelperExtended.VisualDescendantFilterCallback method.
public static DependencyObject? GetFirstDescendant(DependencyObject source, Type desiredType, VisualTreeHelperExtended.VisualDescendantFilterCallback? filterCallback)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
| desiredType | Type | The desired descendant Type. |
| filterCallback | VisualTreeHelperExtended.VisualDescendantFilterCallback | The filter call back. |
Returns
- DependencyObject
GetFirstDescendant<T>(DependencyObject)
Returns a System.Windows.DependencyObject value that represents the first descendant visual object that is of the specified Type.
public static T? GetFirstDescendant<T>(DependencyObject source) where T : class
- Type Parameters:
-
T-The desired descendant Type.
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
Returns
- T
GetFirstFocusableAncestor(DependencyObject)
Returns a UIElement value that represents the first ancestor visual object that is focusable.
public static UIElement? GetFirstFocusableAncestor(DependencyObject source)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose ancestor is returned. |
Returns
GetFirstFocusableDescendant(DependencyObject)
Returns a UIElement value that represents the first descendant visual object that is focusable.
public static UIElement? GetFirstFocusableDescendant(DependencyObject source)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
Returns
GetFirstFocusableDescendant(DependencyObject, VisualDescendantFilterCallback?)
Returns a 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 | DependencyObject | The visual whose descendant is returned. |
| filterCallback | VisualTreeHelperExtended.VisualDescendantFilterCallback | The filter call back. |
Returns
GetFirstTabStopDescendant(DependencyObject)
Returns a Control value that represents the first descendant visual object that is a tab stop.
public static Control? GetFirstTabStopDescendant(DependencyObject source)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose descendant is returned. |
Returns
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 Panel value that represents the items panel of the specified ItemsControl.
public static Panel? GetItemsPanel(ItemsControl source)
| Parameter | Type | Description |
|---|---|---|
| source | ItemsControl | The visual whose items panel is returned. |
Returns
GetNextFocusable(DependencyObject, DependencyObject)
Returns a UIElement value that represents the next visual object that is focusable.
public static UIElement? GetNextFocusable(DependencyObject source, DependencyObject root)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual used as a basis for the search. |
| root | DependencyObject | The root visual used to limit the scope of the search. |
Returns
GetNextFocusable(DependencyObject, DependencyObject, bool)
Returns a 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 | DependencyObject | The visual used as a basis for the search. |
| root | DependencyObject | The root visual used to limit the scope of the search. |
| examineSourceDescendants | bool | Whether the descendants of |
Returns
GetPreviousFocusable(DependencyObject, DependencyObject)
Returns a UIElement value that represents the previous visual object that is focusable.
public static UIElement? GetPreviousFocusable(DependencyObject source, DependencyObject root)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual used as a basis for the search. |
| root | DependencyObject | The root visual used to limit the scope of the search. |
Returns
GetRoot(DependencyObject)
Returns the root System.Windows.DependencyObject in the visual tree.
public static DependencyObject GetRoot(DependencyObject source)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual whose root is returned. |
Returns
- DependencyObject
GetVisualParent(DependencyObject, bool)
Returns the visual parent of the specified source visual.
public static DependencyObject? GetVisualParent(DependencyObject source, bool includeContentElements)
| Parameter | Type | Description |
|---|---|---|
| source | DependencyObject | The visual to examine. |
| includeContentElements | bool | If the source is a ContentElement, whether to allow its logical parent to be returned. |
Returns
- DependencyObject
InvalidateMeasureForAllVisualsInSameTemplate(UIElement?)
Invalidates measurement of all elements within the same source templated UIElement.
public static void InvalidateMeasureForAllVisualsInSameTemplate(UIElement? sourceTemplatedElement)
| Parameter | Type | Description |
|---|---|---|
| sourceTemplatedElement | UIElement | The source templated 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 | 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 | UIElement | The container to examine. |
| direction | FocusNavigationDirection | The direction of focus to be examined, either |
Returns
- bool:
trueif currently positioned at a focus edge; otherwisefalse.
Exceptions
| Type | Condition |
|---|---|
| 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 | DependencyObject | The possible ancestor. |
| source | DependencyObject | The initial object to examine. |
Returns
- bool:
trueif the source System.Windows.DependencyObject is a descendant of the possible ancestor System.Windows.DependencyObject; otherwise,false.
Remarks
This method primarily searches the visual tree but will merge a popup into the hierarchy of either its logical parent or placement target.
IsFocusable(UIElement)
Returns whether the specified UIElement is focusable.
public static bool IsFocusable(UIElement element)
| Parameter | Type | Description |
|---|---|---|
| element | UIElement | The UIElement to examine. |
Returns
IsInMainFocusScope()
Returns whether the element currently with keyboard focus is in the main focus scope.
public static bool IsInMainFocusScope()
Returns
- bool:
trueif 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 | DependencyObject | The element to examine. |
Returns
- bool:
trueif the specified element isnullor 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 | DependencyObject |
|
| e | DragEventArgs | A DragEventArgs that can be used to determine mouse position. |
Returns
- bool:
trueif the bounds of the element contain the mouse position; otherwise,false.
Remarks
The specified object must be a 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 | DependencyObject |
|
| e | MouseEventArgs | A MouseEventArgs that can be used to determine mouse position. |
Returns
- bool:
trueif the bounds of the element contain the mouse position; otherwise,false.
Remarks
The specified object must be a 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 | DependencyObject | The possible ancestor. |
| source | DependencyObject | The initial object to examine. |
Returns
- bool:
trueif the source System.Windows.DependencyObject is the same as or a descendant of the possible ancestor System.Windows.DependencyObject; otherwise,false.
Remarks
This method primarily searches the visual tree but will merge a popup into the hierarchy of either its logical parent or placement target.
IsVisual(DependencyObject?)
public static bool IsVisual(DependencyObject? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | DependencyObject | The System.Windows.DependencyObject to examine. |