How to change state via toggle method in Blazor Toggle Switch Button

27 Aug 20261 minute to read

This section explains how to programmatically toggle the state of the Blazor Toggle Switch Button by flipping the value bound to the Checked property.

@using Syncfusion.Blazor.Buttons

<SfSwitch @bind-Checked="isChecked" OffLabel="OFF" OnLabel="ON" TChecked="bool"></SfSwitch>
<br />
<SfButton Content="Toggle Switch State" OnClick="ToggleState"></SfButton>

@code{
    private bool isChecked = false;
    private void ToggleState()
    {
        isChecked = !isChecked;
    }
}

Changing Blazor Toggle Switch Button State

NOTE

The Switch triggers the ValueChange event on every state change to perform custom operations.