Demos About Radzen
Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    ComponentBase
    RadzenComponent
    FormComponent<bool>
    RadzenSwitch
    Implements
    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormComponent
    Inherited Members
    FormComponent<bool>._value
    FormComponent<bool>.SetParametersAsync(ParameterView)
    FormComponent<bool>.Dispose()
    FormComponent<bool>.GetValue()
    FormComponent<bool>.OnContextMenu(MouseEventArgs)
    FormComponent<bool>.GetClassList(string)
    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
    RadzenComponent.OnMouseEnter()
    RadzenComponent.OnMouseLeave()
    RadzenComponent.GetCssClass()
    RadzenComponent.GetId()
    RadzenComponent.Debounce(Func<Task>, int)
    RadzenComponent.OnInitialized()
    RadzenComponent.OnAfterRenderAsync(bool)
    RadzenComponent.RaiseContextMenu(MouseEventArgs)
    RadzenComponent.RaiseMouseEnter()
    RadzenComponent.AddContextMenu()
    RadzenComponent.RaiseMouseLeave()
    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(bool)
    ComponentBase.InvokeAsync(Action)
    ComponentBase.InvokeAsync(Func<Task>)
    ComponentBase.DispatchExceptionAsync(Exception)
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    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

    true if the switch is read-only; otherwise, false. Default is false.

    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
    ComponentBase.BuildRenderTree(RenderTreeBuilder)

    GetComponentCssClass()

    Gets the component CSS class.

    Declaration
    protected override string GetComponentCssClass()
    Returns
    Type Description
    string
    Overrides
    RadzenComponent.GetComponentCssClass()

    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.

    Implements

    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormComponent

    Introducing Radzen Blazor Studio

    Radzen Blazor Studio is a software development environment that empowers developers to design, build and deploy Blazor applications without the traditional hurdles. Write less code and get more done.

    Learn More

    Download Now
    Download Now
    In This Article
    Back to top Radzen Blazor Components, © 2018-2025 Radzen. Source Code licensed under MIT