Partager via


ExtensionMethods.FindAncestor Method

Definition

Overloads

FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>)

Helper method that finds the first ancestor of a given Type in the logical or visual tree.

FindAncestor<TAncestorType>(Visual)

Helper method that finds the first ancestor of a given Type in the logical or visual tree.

FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>)

Helper method that finds the first ancestor in the logical or visual tree that is accepted by the ancestor selector function.

FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>)

Helper method that finds the first ancestor of a given Type in the logical or visual tree.

public:
generic <typename TAncestorType, typename TElementType>
 where TAncestorType : class[System::Runtime::CompilerServices::Extension]
 static TAncestorType FindAncestor(TElementType obj, Func<TElementType, TElementType> ^ parentEvaluator);
public static TAncestorType FindAncestor<TAncestorType,TElementType> (this TElementType obj, Func<TElementType,TElementType> parentEvaluator) where TAncestorType : class;
static member FindAncestor : 'ElementType * Func<'ElementType, 'ElementType> -> 'AncestorType (requires 'AncestorType : null)
<Extension()>
Public Function FindAncestor(Of TAncestorType As Class, TElementType As Class) (obj As TElementType, parentEvaluator As Func(Of TElementType, TElementType)) As TAncestorType

Type Parameters

TAncestorType

The type of ancestor to find.

TElementType

The base type of intermediate elements in the ancestor tree.

Parameters

obj
TElementType

The object at which to begin searching.

parentEvaluator
Func<TElementType,TElementType>

The method used to determine the parent of an element.

Returns

TAncestorType

The first ancestor of type T in the parent chain of obj, or null if no ancestor is found.

Applies to

FindAncestor<TAncestorType>(Visual)

Helper method that finds the first ancestor of a given Type in the logical or visual tree.

public:
generic <typename TAncestorType>
 where TAncestorType : System::Windows::DependencyObject[System::Runtime::CompilerServices::Extension]
 static TAncestorType FindAncestor(System::Windows::Media::Visual ^ obj);
public static TAncestorType FindAncestor<TAncestorType> (this System.Windows.Media.Visual obj) where TAncestorType : System.Windows.DependencyObject;
static member FindAncestor : System.Windows.Media.Visual -> 'AncestorType (requires 'AncestorType :> System.Windows.DependencyObject)
<Extension()>
Public Function FindAncestor(Of TAncestorType As DependencyObject) (obj As Visual) As TAncestorType

Type Parameters

TAncestorType

The type of ancestor to find.

Parameters

obj
Visual

The object at which to begin searching.

Returns

TAncestorType

The first ancestor of type T in the parent chain of obj, or null if no ancestor is found.

Remarks

The type of obj is Visual rather than DependencyObject in order to disambiguate this method from Microsoft.VisualStudio.PlatformUI.Shell.ExtensionMethods.FindAncestor(ViewElement element). If you need to find an ancestor of a non-Visual DependencyObject you should call FindAncestor<TAncestorType, DependencyObject>(obj, GetVisualOrLogicalParent) directly.

Applies to

FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>)

Helper method that finds the first ancestor in the logical or visual tree that is accepted by the ancestor selector function.

public:
generic <typename TElementType>
[System::Runtime::CompilerServices::Extension]
 static System::Object ^ FindAncestor(TElementType obj, Func<TElementType, TElementType> ^ parentEvaluator, Func<TElementType, bool> ^ ancestorSelector);
public static object FindAncestor<TElementType> (this TElementType obj, Func<TElementType,TElementType> parentEvaluator, Func<TElementType,bool> ancestorSelector);
static member FindAncestor : 'ElementType * Func<'ElementType, 'ElementType> * Func<'ElementType, bool> -> obj
<Extension()>
Public Function FindAncestor(Of TElementType) (obj As TElementType, parentEvaluator As Func(Of TElementType, TElementType), ancestorSelector As Func(Of TElementType, Boolean)) As Object

Type Parameters

TElementType

The base type of intermediate elements in the ancestor tree.

Parameters

obj
TElementType

The object at which to begin searching.

parentEvaluator
Func<TElementType,TElementType>

The method used to determine the parent of an element.

ancestorSelector
Func<TElementType,Boolean>

The method used to select an ancestor of interest.

Returns

The first ancestor in the parent chain of obj accepted by the the ancestor selector function.

Applies to