Table of Contents

Class TwSwitch<T>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a toggle switch component that allows users to select between two states.

public class TwSwitch<T> : TwBlazorInputComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable

Type Parameters

T
Inheritance
TwSwitch<T>
Implements
Inherited Members

Remarks

Supports two-way data binding through the Value and ValueChanged parameters, enabling parent components to react to changes in the switch's state. The component can be customized with a name and color, and is typically used in forms or settings panels where a binary choice is required.

Constructors

TwSwitch()

public TwSwitch()

Properties

Color

Gets or sets the color of the switch.

[Parameter]
public Color? Color { get; set; }

Property Value

Color?

Name

Gets or sets the name associated with the component.

[Parameter]
public string Name { get; set; }

Property Value

string

Value

Gets or sets the current value of the parameter.

[Parameter]
public T Value { get; set; }

Property Value

T

ValueChanged

Gets or sets the callback that is invoked when the value changes.

[Parameter]
public EventCallback<T> ValueChanged { get; set; }

Property Value

EventCallback<T>

Remarks

Use this property to handle value change events in two-way data binding scenarios. The callback is triggered when the component's value is updated, allowing parent components to respond to the change.

ValueExpression

Gets or sets the expression that identifies the bound value. Set automatically by @bind-Value, it lets an enclosing EditForm or TwForm validate the property the field edits.

[Parameter]
public Expression<Func<T>>? ValueExpression { get; set; }

Property Value

Expression<Func<T>>

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

CreateFieldIdentifier()

Creates the identifier of the model property the field's value is bound to. Input components override this to build it from their value expression (supplied by @bind-Value).

protected override FieldIdentifier? CreateFieldIdentifier()

Returns

FieldIdentifier?

The field identifier, or null when the value is not bound to a property.