ExtensionMethods.FindAncestor<TAncestorType> Method (Visual)
Finds the first ancestor of a given type in the logical or visual tree.
Namespace: Microsoft.VisualStudio.PlatformUI
Assembly: Microsoft.VisualStudio.Shell.12.0 (in Microsoft.VisualStudio.Shell.12.0.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function FindAncestor(Of TAncestorType As DependencyObject) ( _
obj As Visual _
) As TAncestorType
public static TAncestorType FindAncestor<TAncestorType>(
this Visual obj
)
where TAncestorType : DependencyObject
[ExtensionAttribute]
public:
generic<typename TAncestorType>
where TAncestorType : DependencyObject
static TAncestorType FindAncestor(
Visual^ obj
)
static member FindAncestor :
obj:Visual -> 'TAncestorType when 'TAncestorType : DependencyObject
JScript does not support generic types or methods.
Type Parameters
- TAncestorType
The type of ancestor to find.
Parameters
obj
Type: VisualThe object at which to begin searching.
Return Value
Type: TAncestorType
The first ancestor of type T in the parent chain of obj, or nulla null reference (Nothing in Visual Basic) if no ancestor is found
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type Visual. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
The type of obj is the Visual rather than the DependencyObject in order to disambiguate this method from FindAncestor(ViewElement element). If you need to find an ancestor of a non-Visual DependencyObject you should call FindAncestor<TAncestorType, DependencyObject>(obj, GetVisualOrLogicalParent) directly.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.