Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
Control Class
Control Methods
 GetTemplateChild Method
Collapse All/Expand All Collapse All
.NET Framework Class Library for Silverlight
Control..::.GetTemplateChild Method

Retrieves the named element in the instantiated ControlTemplate visual tree.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Protected Function GetTemplateChild ( _
    childName As String _
) As DependencyObject
Visual Basic (Usage)
Dim childName As String
Dim returnValue As DependencyObject

returnValue = Me.GetTemplateChild(childName)
C#
protected DependencyObject GetTemplateChild(
    string childName
)

Parameters

childName
Type: System..::.String
The name of element to find.

Return Value

Type: System.Windows..::.DependencyObject
The named element from the template, if found. Can return nullNothingnullptra null reference (Nothing in Visual Basic) if no element with name childName was found in the template.

Templates in Silverlight 2 have a self-contained namescope. This is because templates are re-used, and any name defined in a template cannot remain unique once multiple instances of a control each instantiate their template. Call GetTemplateChild in order to return references to objects that come from the template after it is instantiated. You cannot use FindName to find items from templates because 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.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker