States in Xamarin Switch (SfSwitch)

22 Aug 20223 minutes to read

Switch allows you to configure the states as explained in the following sections.

On

You can switch to on state by tapping the 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;

switch control is displaying on state

Off

This is the default state. You can switch to off state by tapping the switch button or by defining as demonstrated in the following code example.

<syncfusion:SfSwitch IsOn="False" />
SfSwitch sfSwitch = new SfSwitch();

sfSwitch.IsOn = false;

switch control displaying off state

Indeterminate

The indeterminate state can be enabled when you need to display the work progress. The following code example demonstrates how to load the switch in indeterminate state by setting the IsOn property to null.

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

sfSwitch.IsOn = null;

sfSwitch.AllowIndeterminateState = true;

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 IsEnabled property as false.

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

switch control displaying disabled on state

Disabled Off

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

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

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 IsOn property value as null and 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;

switch conrol displaying disabled indeterminate state