Style property
Collapse the table of content
Expand the table of content

FrameworkElement.Style property

Gets or sets an instance Style that is applied for this object during layout and rendering.


public Style Style { get; set; }

<frameworkElement Style="{StaticResource styleResourceKey}"/>

XAML Values


The key that identifies the style being requested. The key refers to an existing resource in a ResourceDictionary.

Note  XAML property element syntax to define an inline style is technically possible, but not recommended for setting FrameworkElement.Style. This is because any property set through a single-use inline style could just as easily have been set by directly setting the property as a XAML attribute (or property element). Defining a one-use style to set that same property is generally poor markup style and can cause a confusing run-time property setting behavior.

Property value

Type: Style

The applied style for the object, if present; otherwise, null. The default for a default-constructed FrameworkElement is null.


Setting the Style property directly is not the most common way to style a UI element's appearance. Instead, you influence a UI element's appearance through one of the these techniques:

  • You often set individual UI properties of a UI element as attributes in XAML. FrameworkElement.Style only applies to the current element, and any value from a StyleFrameworkElement.Style is overwritten by a local property value, so setting the local value is more direct and more predictable. For more info on how a Style value and a local property value relate, see Dependency properties overview.
  • Control authors typically write a control that is templatable, but also comes with a default template. Your app can use the control and change its appearance by providing a new ControlTemplate, which is part of a Style defined in resources. This style is typically applied using the implicit style feature, not by setting Style. For more info, see Styling controls.
  • Control authors also expose properties that reference parts of a control that can have styles or values applied to just that part, so you don't have to totally retemplate the control. Here you're setting a more specific property, not FrameworkElement.Style.
  • The visual state model frequently resets the style of control at run time in response to changes in states that manifest themselves to the users visually. For example, control templates typically have a "Focused" state that adds a visual focus indicator to the control appearance so that a keyboard user can see which element in UI has the current keyboard focus. For more info on the visual state concept, see Quickstart: Control templates.

You can change the values of individual properties that have been set within a style. For example, you can set the Template property at run time even if this property has been set by a style. Or you can add setters to the collection in Setters. However, as soon as that style is placed in use by a loaded object, the Style should be considered sealed. You can detect this state by checking the value of IsSealed for the Style. A style is considered to be in use as soon as it is referenced by a loaded object that is connected to the object tree of a displayed page of UI. A Style and its Setters can also be considered sealed when the object using that style raises its Loaded event. Attempting to change an individual property of an in-use style (such as a property in the Setters collection) throws an exception.

Classes derived from Control have an additional entry point that is useful to control authors in regard to style and template application. FrameworkElement defines the virtual callback OnApplyTemplate that is invoked prior to Loaded. Classes derived from Control can override this callback to adjust the property values that were set by templates before the style is in use.

If queried at run time, the Style property does not return styles that come from an applied template, or active visual states. It only returns styles that were explicitly set by the Style property. In addition, it does not return implicit styles.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]



See also

Styling controls



© 2016 Microsoft