Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 2
 OnApplyTemplate Method

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 2

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
FrameworkElement..::.OnApplyTemplate Method

Updated: November 2008

When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Overridable Sub OnApplyTemplate
Visual Basic (Usage)
Dim instance As FrameworkElement

instance.OnApplyTemplate()
C#
public virtual void OnApplyTemplate()

Silverlight template support is not fully enabled on FrameworkElement. Instead, Silverlight provides template support for Control, which is an immediate subclass of FrameworkElement, as well as a specialized template behavior for ContentPresenter. OnApplyTemplate is defined at the FrameworkElement level for WPF compatibility reasons.

Notes to Inheritors:

This method potentially has a native implementation (which is referenced by the default implementation), so you should always call the base implementation.

Derived classes can use this method as a notification/entry point to:

  • Build the remainder of a visual tree using custom code.

  • Run code that relies on the visual tree from templates having been applied, such as obtaining references to named elements that came from a template.

  • Introduce services that only make sense to exist after the visual tree from templates is complete.

  • Set states and properties of elements within the template that are dependent on other factors. For instance, property values might only be discoverable by knowing the parent element, or when a specific derived class uses a common template. However, note that a well-designed control should generally handle its visual and behavioral states through VisualStateManager. For details on this concept, see Control Customization.

OnApplyTemplate is a more appropriate point to deal with adjustments to the template-created visual tree than is the Loaded event. In Silverlight, the Loaded event might occur before the template is applied, and thus you might not be able to adjust the visual tree that is created through the template in a Loaded handler. For more information, see the Remarks for Loaded.

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

Date

History

Reason

November 2008

Added comparison to the Loaded event.

Content bug fix.

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
Page view tracker