States in .NET MAUI Switch (SfSwitch)

21 May 20253 minutes to read

The .NET MAUI Switch allows you to configure various states as explained in the following sections.

On state

You can switch to the “On” state by tapping the .NET MAUI Switch button or by setting a value, as demonstrated in the following code example.

<syncfusion:SfSwitch IsOn="True" />
SfSwitch sfSwitch=new SfSwitch();
sfSwitch.IsOn=true;
this.Content = sfSwitch;

On state.

Off state

This is the default state. You can switch to the “Off” state by tapping the .NET MAUI Switch button or by defining it, as demonstrated in the following code example.

<syncfusion:SfSwitch IsOn="False" />
SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = false;
this.Content = sfSwitch;

Off state.

Indeterminate state

The indeterminate state can be enabled by using the AllowIndeterminateState property when you need to display the work progress. The following code example demonstrates how to load the .NET MAUI Switch in an Indeterminate state by setting the IsOn property to null.

<syncfusion:SfSwitch IsOn="{x:Null}" AllowIndeterminateState="True" />
SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = null;
this.Content = sfSwitch;

sfSwitch.AllowIndeterminateState = true;

Indeterminate state.

NOTE

By default, the switch control has only two states: on and off.

Disabled On state

You can switch to the disabled “On” state by setting the IsOn property to true and the IsEnabled property to false.

<syncfusion:SfSwitch IsOn="True" IsEnabled="False" />
SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = true;
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;

Disabled On state.

Disabled Off state

You can switch to the disabled “Off” state by setting the IsOn property to false and the IsEnabled property to false.

<syncfusion:SfSwitch IsOn="False" IsEnabled="False" />
SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = false;
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;

Disabled off state.

Disabled indeterminate state

The disabled indeterminate state can be enabled when you need to display the work progress. The below code example demonstrates loading the switch in a disabled indeterminate state by setting the IsOn property value to null and the IsEnabled property to false.

<syncfusion:SfSwitch AllowIndeterminateState="True" IsOn="{x:Null}" IsEnabled="False"/>
SfSwitch sfSwitch = new SfSwitch();
sfSwitch.AllowIndeterminateState = true;
sfSwitch.IsOn = null;          
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;

Disabled indeterminate state.