Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FrameworkElement.OnApplyTemplate Method

When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
public virtual void OnApplyTemplate()

This method has no default implementation.

Templates are the section of an element's completed visual tree that comes from the Template property of a Style that is applied for the element. For more information, see Styling and Templating.

Notes to Inheritors

Derived classes of FrameworkElement can use this method as a notification for a variety of possible scenarios:

  • You can call your own implementation of code that builds the remainder of an element visual tree.

  • You can 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.

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

  • You can 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.

Implementers should always call the base implementation before their own implementation. FrameworkElement itself has no default implementation, but intervening classes might.

Control offers a similar override, Control.OnTemplateChanged.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.