Class RadzenSwitch
A toggle switch component for boolean on/off states with a sliding animation. RadzenSwitch provides an alternative to checkboxes with a more modern toggle UI pattern, ideal for settings and preferences. Displays as a sliding toggle that users can click or drag to change between on (true) and off (false) states, providing visual feedback with a sliding animation and color change. Common uses include enabling/disabling settings or features, toggling visibility of sections, on/off preferences in configuration panels, and boolean options in forms. Supports keyboard navigation (Space/Enter to toggle) for accessibility. Unlike checkboxes, switches are typically used for immediate effects rather than form submission actions.
Inherited Members
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
Syntax
public class RadzenSwitch : FormComponent<bool>, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, IRadzenFormComponent
Examples
Basic switch:
<RadzenSwitch @bind-Value=@isEnabled />
Switch with label and change event:
<RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center">
<RadzenSwitch @bind-Value=@notifications Change=@(enabled => Console.WriteLine($"Notifications: {enabled}")) />
<RadzenLabel Text="Enable notifications" />
</RadzenStack>
Read-only switch for display:
<RadzenSwitch Value=@feature.IsEnabled ReadOnly="true" />
Constructors
RadzenSwitch()
A toggle switch component for boolean on/off states with a sliding animation. RadzenSwitch provides an alternative to checkboxes with a more modern toggle UI pattern, ideal for settings and preferences. Displays as a sliding toggle that users can click or drag to change between on (true) and off (false) states, providing visual feedback with a sliding animation and color change. Common uses include enabling/disabling settings or features, toggling visibility of sections, on/off preferences in configuration panels, and boolean options in forms. Supports keyboard navigation (Space/Enter to toggle) for accessibility. Unlike checkboxes, switches are typically used for immediate effects rather than form submission actions.
Declaration
public RadzenSwitch()
Examples
Basic switch:
<RadzenSwitch @bind-Value=@isEnabled />
Switch with label and change event:
<RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center">
<RadzenSwitch @bind-Value=@notifications Change=@(enabled => Console.WriteLine($"Notifications: {enabled}")) />
<RadzenLabel Text="Enable notifications" />
</RadzenStack>
Read-only switch for display:
<RadzenSwitch Value=@feature.IsEnabled ReadOnly="true" />
Properties
InputAttributes
Gets or sets additional HTML attributes to be applied to the underlying input element. This allows passing custom attributes like data-* attributes, aria-* attributes, or other HTML attributes directly to the input.
Declaration
[Parameter]
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | A dictionary of custom HTML attributes. |
ReadOnly
Gets or sets whether the switch is read-only and cannot be toggled by user interaction. When true, the switch displays its current state but prevents clicking or keyboard toggling. Useful for displaying switch state in view-only forms or dashboards.
Declaration
[Parameter]
public bool ReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
BuildRenderTree(RenderTreeBuilder)
A toggle switch component for boolean on/off states with a sliding animation. RadzenSwitch provides an alternative to checkboxes with a more modern toggle UI pattern, ideal for settings and preferences. Displays as a sliding toggle that users can click or drag to change between on (true) and off (false) states, providing visual feedback with a sliding animation and color change. Common uses include enabling/disabling settings or features, toggling visibility of sections, on/off preferences in configuration panels, and boolean options in forms. Supports keyboard navigation (Space/Enter to toggle) for accessibility. Unlike checkboxes, switches are typically used for immediate effects rather than form submission actions.
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
| Type | Name | Description |
|---|---|---|
| RenderTreeBuilder | __builder |
Overrides
GetComponentCssClass()
Gets the component CSS class.
Declaration
protected override string GetComponentCssClass()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Toggle()
Programmatically toggles the switch between on (true) and off (false) states. This method is public and can be called from code to toggle the switch without user interaction. Does nothing if the switch is disabled or read-only.
Declaration
public Task Toggle()
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous toggle operation. |