Skip to content

StyleBuilder Struct

Ed Charbeneau edited this page Jan 16, 2020 · 1 revision

Creates a StyleBuilder used to define conditional inline styles used in a component. Call Build() to return the completed style as a string. StyleBuilder has a traditional constructor and two functional (static) convenience methods.

public struct StyleBuilder

Constructors

Creates a StyleBuilder used to define conditional inline style used in a component. Call Build() to return the completed style as a string.

new StyleBuilder(string, string)

Initializes a new instance of the StyleBuilder struct.

public StyleBuilder(string prop, string value)

Examples

string StyleToRender =>
         new StyleBuilder("color", "white")
         .AddStyle("border", "1px solid black")
       .Build();
// StyleToRender: "color:white;border:1px solid black"

StyleBuilder.Default(string, string)

Initializes a new instance of the StyleBuilder struct with a default initial value.

public static StyleBuilder Default(string prop, string value)

Examples

string StyleToRender =>
         StyleBuilder.Default("color", "white")
         .AddStyle("border", "1px solid black")
       .Build();
// StyleToRender: "color:white;border:1px solid black"

StyleBuilder.Empty()

Initializes a new instance of the StyleBuilder struct with a string.Empty value.

public static StyleBuilder Empty()

Examples

string StyleToRender =>
         StyleBuilder.Empty()
         .AddStyle("border", "1px solid black", when: true)
       .Build();
// StyleToRender: "border:1px solid black"