Control.GetTemplateChild(String) 方法

定义

检索实例化的 ControlTemplate 可视化树中的命名元素。

protected:
 virtual DependencyObject ^ GetTemplateChild(Platform::String ^ childName) = GetTemplateChild;
DependencyObject GetTemplateChild(winrt::hstring const& childName);
protected DependencyObject GetTemplateChild(string childName);
function getTemplateChild(childName)
Protected Function GetTemplateChild (childName As String) As DependencyObject

参数

childName
String

Platform::String

winrt::hstring

要查找的元素的名称。

返回

如果找到该元素,则为模板中的命名元素。 如果在模板中找不到名为 childName 的元素,则可以返回 null。

注解

调用 GetTemplateChild 以在实例化控件 模板 后获取对对象的引用。 ControlTemplateOnApplyTemplate 方法中实例化。 可以在 OnApplyTemplate 重写中使用 GetTemplateChild 方法,并保留对所需对象的引用。

适用于

另请参阅