States in .NET MAUI Switch (SfSwitch)
24 Jul 20264 minutes to read
The .NET MAUI Switch allows you to configure various states as explained in the following sections.
Prerequisites
Before using the SfSwitch, ensure the following NuGet package is installed in your .NET MAUI project:
Syncfusion.Maui.Buttons
For a step-by-step setup, refer to the Getting Started documentation.
On state
Set the IsOn property to true or tap the Switch to put it in the On state.
<syncfusion:SfSwitch x:Name="sfSwitch" IsOn="True" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = true;
this.Content = sfSwitch;
Off state
Set the IsOn property to false or tap the Switch to put it in the Off state. This is the default state.
<syncfusion:SfSwitch x:Name="sfSwitch" IsOn="False" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = false;
this.Content = sfSwitch;
Indeterminate state
Use the Indeterminate state to display in-progress work, such as a partially completed task. Enable it by setting AllowIndeterminateState to true and IsOn to null.
<syncfusion:SfSwitch x:Name="sfSwitch" IsOn="{x:Null}"
AllowIndeterminateState="True" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.AllowIndeterminateState = true;
sfSwitch.IsOn = null;
this.Content = sfSwitch;
Disabled On state
Set the IsOn property to true and the IsEnabled property to false to put the Switch in the disabled On state.
<syncfusion:SfSwitch x:Name="sfSwitch" IsOn="True"
IsEnabled="False" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = true;
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;
Disabled Off state
Set the IsOn property to false and the IsEnabled property to false to put the Switch in the disabled Off state.
<syncfusion:SfSwitch x:Name="sfSwitch" IsOn="false"
IsEnabled="false" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.IsOn = false;
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;
Disabled Indeterminate state
Set AllowIndeterminateState to true, IsOn to null, and IsEnabled to false to put the Switch in the disabled Indeterminate state.
<syncfusion:SfSwitch x:Name="sfSwitch"
AllowIndeterminateState="True"
IsOn="{x:Null}"
IsEnabled="False" />SfSwitch sfSwitch = new SfSwitch();
sfSwitch.AllowIndeterminateState = true;
sfSwitch.IsOn = null;
sfSwitch.IsEnabled = false;
this.Content = sfSwitch;