Table of Contents

Class TwCheckbox<T>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a generic checkbox input component for Blazor that supports two-way data binding and customizable value types.

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

Type Parameters

T

The type of value associated with the checkbox. Determines the data type used for binding and value changes.

Inheritance
TwCheckbox<T>
Implements
Inherited Members

Remarks

Use TwCheckbox<T> to create checkbox inputs that bind to values of type T. The component supports two-way binding via the Value and ValueChanged parameters. The Name property can be used to associate the checkbox with a form field or for accessibility purposes.

Constructors

TwCheckbox()

public TwCheckbox()

Properties

Color

Gets or sets the color of the checkbox.

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

Property Value

Color?

GroupName

Gets or sets the name from a parent CheckboxGroup (cascaded value).

[CascadingParameter(Name = "GroupName")]
public string? GroupName { get; set; }

Property Value

string

Name

Gets or sets the name associated with the component.

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

Property Value

string

Size

Gets or sets the size of the checkbox and its check/dash icon. Defaults to Md, the same dimensions this component has always rendered at.

[Parameter]
public Size Size { get; set; }

Property Value

Size

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.

OnAfterRenderAsync(bool)

Method invoked after each time the component has been rendered interactively and the UI has finished updating (for example, after elements have been added to the browser DOM). Any ElementReference fields will be populated by the time this runs.

This method is not invoked during prerendering or server-side rendering, because those processes are not attached to any live browser DOM and are already complete before the DOM is updated.

Note that the component does not automatically re-render after the completion of any returned Task, because that would cause an infinite render loop.

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Set to true if this is the first time OnAfterRender(bool) has been invoked on this component instance; otherwise false.

Returns

Task

A Task representing any asynchronous operation.

Remarks

The OnAfterRender(bool) and OnAfterRenderAsync(bool) lifecycle methods are useful for performing interop, or interacting with values received from @ref. Use the firstRender parameter to ensure that initialization work is only performed once.