April 12, 2014
Gets or sets an instance Style that is applied for this object during rendering.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
XAML property element syntax to define an inline style is technically possible, but not recommended for setting . 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.
Dependency property identifier field: StyleProperty
Setting the Style property directly is not the most common way to style a UI element's appearance in Windows Phone. Instead, it is more common to influence a UI element's appearance through one of the following techniques:
Control authors write a control that is templatable. Applications that use the control can change its appearance by providing a new ControlTemplate.
Control authors define a default style that is applied to all instances of the control. Control authors also expose properties that reference composite objects within a style or template, such that specific appearance aspects of the control can be adjusted by properties without having to adjust either the style or template. (You could style such properties, as the control consumer, but could also more easily set them directly as attributes in the XAML declarations.)
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 and the Windows Phone root visual. This point in time can be detected when the object where the Style property is set 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, in order to apply non-templated values to the template-created properties for that instance of the control.
If queried at run time, the property does not return styles that come from an applied template. It only returns styles that were explicitly and previously set by the property. In addition, it does not return implicit styles. For more information about the implicit style concept, see Style.