Skip to main content
FrameworkElementGetTemplateChild Method
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns the named element in the visual tree of an instantiated ControlTemplate.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

protected internal DependencyObject GetTemplateChild(
	string childName
)
public protected:
DependencyObject^ GetTemplateChild(
	String^ childName
)
member GetTemplateChild : 
        childName:string -> DependencyObject
Protected Friend Function GetTemplateChild (
	childName As String
) As DependencyObject

Parameters

childName
Type:

Name of the child to find.

Return Value

Type:

The requested element. May be null if no element of the requested name exists.

Templates in WPF have a self-contained namescope. This is because templates are re-used, and any name defined in a template cannot remain unique when multiple instances of a control each instantiate its template. Call the GetTemplateChild method to return references to objects that come from the template after it is instantiated. You cannot use the FrameworkElementFindName method to find items from templates because FrameworkElementFindName acts in a more general scope, and there is no connection between the ControlTemplate class itself and the instantiated template once it is applied.

FrameworkTemplateFindName supplies the same function as this method. FrameworkTemplateFindName is public instead of protected, and it uses correct name-scoping considerations that allow it to access the template within an element and find named items within it. Use FrameworkTemplateFindName when you need to get an element outside of its parent control.

.NET Framework
Available since 3.0
Return to top