Class Style<TTarget>
A strongly-typed, fluent builder over Style for defining styles in C# code with compile-time-checked, IntelliSense-friendly property references instead of string-keyed setters.
public class Style<TTarget> : Style, IImplicitResourceKey where TTarget : UIElement
Type Parameters
TTargetThe type of element this style is meant to be applied to.
- Inheritance
-
Style<TTarget>
- Implements
- Inherited Members
- Extension Methods
Remarks
Set<TValue>(Expression<Func<TTarget, TValue>>, TValue) resolves the target property's name and writes it into the same underlying Setters dictionary the string-keyed API and markup use, so both authoring styles stay interchangeable and go through the exact same Apply(UIElement) logic.
Constructors
Style()
Initializes a new instance of the Style<TTarget> class.
public Style()
Methods
InheritsFrom(Style)
Sets the style this style inherits setters and state groups from, and returns this style for further chaining.
public Style<TTarget> InheritsFrom(Style baseStyle)
Parameters
baseStyleStyleThe style to inherit from.
Returns
- Style<TTarget>
This style, for fluent chaining.
Set<TValue>(Expression<Func<TTarget, TValue>>, TValue)
Sets the value a property this style targets should have, and returns this style for further chaining.
public Style<TTarget> Set<TValue>(Expression<Func<TTarget, TValue>> property, TValue value)
Parameters
propertyExpression<Func<TTarget, TValue>>A simple property-access expression identifying the property to set, e.g.
x => x.Background.valueTValueThe value to set.
Returns
- Style<TTarget>
This style, for fluent chaining.
Type Parameters
TValueThe type of the property's value.
WithStateGroup(VisualStateGroup)
Adds a visual-state group this style registers on every element it's applied to, and returns this style for further chaining.
public Style<TTarget> WithStateGroup(VisualStateGroup group)
Parameters
groupVisualStateGroupThe group to add.
Returns
- Style<TTarget>
This style, for fluent chaining.