States in .NET MAUI Switch (SfSwitch)

21 Aug 20243 minutes to read

The .NET MAUI Switch allows you to configure the 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;

.NET MAUI Switch control is displaying 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;

.NET MAUI Switch control displaying off state.

Indeterminate State

The indeterminate state can be enabled by using 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;

.NET MAUI Switch conrol is displaying indeterminate state.

NOTE

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

Disabled On

You can switch to disabled on state by setting the IsOn property as true and the IsEnabled property as false.

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

.NET MAUI Switch control displaying disabled on state.

Disabled Off

You can switch to disabled off state by setting the IsOn property as false and the IsEnabled property as false.

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

.NET MAUI Switch control displaying disabled off state.

Disabled Indeterminate

The disabled indeterminate state can be enabled when you need to display the work progress. The below code example demonstrates loading the switch in disabled indeterminate state by setting the IsOn property value as null and the IsEnabled property as 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;

.NET MAUI Switch conrol displaying disabled indeterminate state.