Control.GetTemplateChild(String) Method

Definition

Retrieves the named element in the instantiated ControlTemplate visual tree.

C#
protected DependencyObject GetTemplateChild(string childName);

Parameters

childName
String

The name of the element to find.

Returns

The named element from the template, if the element is found. Can return null if no element with name childName was found in the template.

Remarks

You call GetTemplateChild to get references to objects in a controls Template after it's instantiated. The ControlTemplate is instantiated in the OnApplyTemplate method. You can use the GetTemplateChild method inside your OnApplyTemplate override and keep a reference to the objects you need.

Applies to

Product Versions
Windows App SDK 0.8, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6

See also