Class Style
Represents a set of property values (and, optionally, VisualStateGroups) applied to every UIElement whose Style is set to this instance.
[MarkupSetterCollection("Setters")]
public class Style : IImplicitResourceKey
- Inheritance
-
Style
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
Style(Type)
Represents a set of property values (and, optionally, VisualStateGroups) applied to every UIElement whose Style is set to this instance.
public Style(Type targetType)
Parameters
targetTypeTypeThe type of element this style is meant to be applied to.
Properties
BasedOn
Gets or sets a style this style inherits setters and state groups from.
public Style? BasedOn { get; set; }
Property Value
Remarks
Applied first, so this style's own setters/state groups take precedence when both set the same property.
ReplacesTheme
Gets or sets a value indicating whether this style replaces the theme's style for its type instead of being applied on top of it. false by default.
public bool ReplacesTheme { get; set; }
Property Value
Remarks
A style that isn't the theme's own (a keyed style, or an implicit style in an element's Resources) is applied over the theme's style for its type: the theme supplies the template, colors and visual states, and this style changes only what it sets. Set this to true for a control that should look like nothing but this style, for example a text box drawn without the theme's border inside another control.
Setters
Gets the property values this style sets, keyed by property name.
public Dictionary<string, object?> Setters { get; }
Property Value
Remarks
Resolved against PropertyRegistry when applied (see Apply(UIElement)), so only properties registered via RegisterReferenceAttribute (or an attached property) can be targeted by name here.
StateGroups
Gets the visual-state groups this style registers on every element it's applied to.
public List<VisualStateGroup> StateGroups { get; }
Property Value
TargetType
Gets the type of element this style is meant to be applied to.
public Type TargetType { get; }
Property Value
Methods
Apply(UIElement)
Applies this style's setters and state groups to control.
public void Apply(UIElement control)
Parameters
controlUIElementThe element to apply this style to.
Exceptions
- InvalidOperationException
This style's BasedOn chain contains a cycle.