Compartir a través de


Control.ApplyTemplate Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Loads the relevant control template so that its parts can be referenced.

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

Syntax

'Declaration
Public Function ApplyTemplate As Boolean
public bool ApplyTemplate()

Return Value

Type: System.Boolean
Returns whether the visual tree was rebuilt by this call. true indicates the tree was rebuilt; false indicates that the previous visual tree was retained.

Remarks

For typical element logic within applications, such as when consuming existing controls, calling ApplyTemplate is not necessary, because templates will be applied to elements at an appropriate point in their lifetimes automatically. ApplyTemplate is generally speaking used only by authors of controls.

Call this method for cases where a control is the parent of another templated control, and the child control template must exist so that the parent control can apply all necessary state and run-time property setting in the parent's instantiation logic.

Any layout pass that generates a new layout will also call ApplyTemplate on a control.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

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