RadzenSwitch Class

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.

Inheritance

Object

ComponentBase

RadzenComponent

FormComponent<bool>

RadzenSwitch

Implements

IComponent

IHandleEvent

IHandleAfterRender

IRadzenFormComponent

Inherited Members

FormComponent<bool>.SetParametersAsync

FormComponent<bool>.Dispose

FormComponent<bool>.GetValue

FormComponent<bool>.OnContextMenu

FormComponent<bool>.GetClassList

FormComponent<bool>.FocusAsync

FormComponent<bool>.Name

FormComponent<bool>.TabIndex

FormComponent<bool>.Placeholder

FormComponent<bool>.Disabled

FormComponent<bool>.EditContext

FormComponent<bool>.Form

FormComponent<bool>.ValueChanged

FormComponent<bool>.HasValue

FormComponent<bool>.IsBound

FormComponent<bool>.Value

FormComponent<bool>.Change

FormComponent<bool>.FieldIdentifier

FormComponent<bool>.ValueExpression

FormComponent<bool>.FormFieldContext

FormComponent<bool>.CurrentPlaceholder

FormComponent<bool>._value

RadzenComponent.OnMouseEnter

RadzenComponent.OnMouseLeave

RadzenComponent.GetCssClass

RadzenComponent.GetId

RadzenComponent.Debounce

RadzenComponent.OnInitialized

RadzenComponent.OnAfterRenderAsync

RadzenComponent.RaiseContextMenu

RadzenComponent.RaiseMouseEnter

RadzenComponent.AddContextMenu

RadzenComponent.RaiseMouseLeave

RadzenComponent.OnBecameInvisible

RadzenComponent.Attributes

RadzenComponent.Element

RadzenComponent.MouseEnter

RadzenComponent.MouseLeave

RadzenComponent.ContextMenu

RadzenComponent.Culture

RadzenComponent.DefaultCulture

RadzenComponent.Style

RadzenComponent.Visible

RadzenComponent.UniqueID

RadzenComponent.JSRuntime

RadzenComponent.IsJSRuntimeAvailable

RadzenComponent.Reference

RadzenComponent.CurrentStyle

ComponentBase.OnInitializedAsync

ComponentBase.OnParametersSet

ComponentBase.OnParametersSetAsync

ComponentBase.StateHasChanged

ComponentBase.ShouldRender

ComponentBase.OnAfterRender

ComponentBase.InvokeAsync

ComponentBase.DispatchExceptionAsync

ComponentBase.RendererInfo

ComponentBase.Assets

ComponentBase.AssignedRenderMode

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenSwitch : FormComponent<bool>, IComponent, IHandleEvent, IHandleAfterRender, 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

RadzenSwitchlink

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()

Properties

InputAttributeslink

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
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
Type Description
IReadOnlyDictionary<string, object>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.

ReadOnlylink

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
public bool ReadOnly { get; set; }
Property Value
Type Description
boolGets 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.

Methods

BuildRenderTreelink

Declaration
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
Parameters
Type Name Description
Rendering.RenderTreeBuilder __builder

GetComponentCssClasslink

Declaration
protected override string GetComponentCssClass()
Returns
Type Description
string

Togglelink

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
TaskA task representing the asynchronous toggle operation.
An error has occurred. This app may no longer respond until reloaded. Reload 🗙