Enables the sharing of properties, resources, and event handlers between instances of a type.
Assembly: PresentationFramework (in PresentationFramework.dll)
Gets or sets a defined style that is the basis of the current style.
Gets a value that indicates whether the style is read-only and cannot be changed.
Gets or sets the collection of resources that can be used within the scope of this style.
Gets or sets the type for which this style is intended.
Gets a collection of TriggerBase objects that apply property values based on specified conditions.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)
Returns the hash code for this Object.GetHashCode().). (Overrides
Registers a new name-object pair in the current namescope.
Locks this style and all factories and triggers so they cannot be changed.
Returns a string that represents the current object.(Inherited from Object.)
Removes a name-object mapping from the namescope.
This API supports the product infrastructure and is not intended to be used directly from your code. Adds a child object.
This API supports the product infrastructure and is not intended to be used directly from your code. Adds the text content of a node to the object.
This API supports the product infrastructure and is not intended to be used directly from your code. Returns an object that has the provided identifying name.
Queries whether a specified ambient property is available in the current scope.
You can set a FrameworkElement or FrameworkContentElement. A style is most commonly declared as a resource inside the Resources section. Because styles are resources, they obey the same scoping rules that apply to all resources, so where you declare a style affects where it can be applied. If, for instance, you declare the style in the root element of your application definition XAML file, the style can be used anywhere in your application. If you are creating a navigation application and declare the style in one of the application's XAML files, the style can be used only in that XAML file. For more information on scoping rules for resources, see XAML Resources.on any element that derives from
The style declaration consists of a Setter objects. Each Setter consists of a Property and a Value. The property is the name of the property of the element the style is to apply to. After the style is declared as a resource, it can then be referenced just like any other resource.object that contains a collection of one or more
If there is more than one setter in the setter collection with the same Property property value, the setter that is declared last is used. Similarly, if you set a value for the same property in a style and on an element directly, the value set on the element directly takes precedence.
The Windows Presentation Foundation (WPF) styling and templating model allows maintenance and sharing of a look as well as the separation of presentation and logic. The styling and templating model includes a suite of features that enable you to customize your UI. This suite of features includes theclass as well as the following:
For more information, see Styling and Templating.
To apply the above style, do the following:
You can also apply styles to all elements of a given type by using the TargetType property. Adding the target type to the style means that you no longer have to fully qualify the property you are setting with the ClassName.PropertyName syntax. The following example defines a style that will be applied to every TextBlock element.
Many WPF controls consist of a combination of other WPF controls, so creating a style that applies to all controls of a type can have broad impact. For instance, if you create a style that targets the TextBlock controls in a Canvas, the style is applied to all TextBlock controls in the canvas, even if the TextBlock is part of another control, such as a ListBox.
For information on how to extend or inherit from a defined style, see the BasedOn page.
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.