Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement.GetTemplateChild Method

Updated: May 2010

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
You cannot use methods in XAML.


Type: System.String

Name of the child to find.

Return Value

Type: System.Windows.DependencyObject
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 FrameworkElement.FindName method to find items from templates because FrameworkElement.FindName acts in a more general scope, and there is no connection between the ControlTemplate class itself and the instantiated template once it is applied.

FrameworkTemplate.FindName supplies the same function as this method. FrameworkTemplate.FindName 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 FrameworkTemplate.FindName when you need to get an element outside of its parent control.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0




May 2010

Corrected summary and enhanced remarks.

Content bug fix.

© 2018 Microsoft