Skip to main content

ToggleSwitch

The ToggleSwitch control presents a sliding toggle that you can flip between on and off states. It behaves like a CheckBox but uses a track-and-thumb visual that feels natural on mobile and touch-first interfaces.

Use ToggleSwitch when you need an immediate on/off setting, such as enabling dark mode or toggling notifications. For form fields where users select multiple options from a list, a CheckBox is usually a better fit.

Common properties

You will probably use these properties most often:

PropertyTypeDescription
IsCheckedbool?Gets or sets the current toggle state. true is on, false is off.
OnContentobjectContent displayed when the toggle is on. Defaults to "On".
OffContentobjectContent displayed when the toggle is off. Defaults to "Off".
KnobTransitionsTransitionsThe transitions applied to the knob during state changes.

Events

EventDescription
IsCheckedChangedRaised when the IsChecked value changes.

Basic example

Place a ToggleSwitch in your AXAML and bind IsChecked to a Boolean property on your view model:

<ToggleSwitch IsChecked="{Binding IsEnabled}" />

Custom on/off labels

You can replace the default "On" and "Off" text with your own strings:

<ToggleSwitch IsChecked="{Binding IsDarkMode}"
OnContent="Dark"
OffContent="Light" />

Hiding the labels

Set both content properties to empty strings to show only the sliding toggle:

<ToggleSwitch IsChecked="{Binding IsActive}"
OnContent=""
OffContent="" />

This is useful when the surrounding layout already provides a label for the setting.

Rich content

You can use any controls as the on and off content. The following example pairs a PathIcon with a TextBlock:

<ToggleSwitch IsChecked="{Binding NotificationsEnabled}">
<ToggleSwitch.OnContent>
<StackPanel Orientation="Horizontal" Spacing="6">
<PathIcon Data="{StaticResource bell_regular}" Width="14" />
<TextBlock Text="Enabled" />
</StackPanel>
</ToggleSwitch.OnContent>
<ToggleSwitch.OffContent>
<StackPanel Orientation="Horizontal" Spacing="6">
<PathIcon Data="{StaticResource bell_off_regular}" Width="14" />
<TextBlock Text="Disabled" />
</StackPanel>
</ToggleSwitch.OffContent>
</ToggleSwitch>

Binding to a view model

Create Boolean properties in your view model and bind each ToggleSwitch to one of them:

public partial class SettingsViewModel : ObservableObject
{
[ObservableProperty]
private bool _isDarkMode;

[ObservableProperty]
private bool _notificationsEnabled = true;

partial void OnIsDarkModeChanged(bool value)
{
// Apply theme change
}
}
<StackPanel Spacing="12">
<ToggleSwitch IsChecked="{Binding IsDarkMode}"
OnContent="Dark Mode" OffContent="Light Mode" />
<ToggleSwitch IsChecked="{Binding NotificationsEnabled}"
OnContent="Notifications On" OffContent="Notifications Off" />
</StackPanel>

Because ToggleSwitch uses two-way binding by default, flipping the toggle immediately updates the view model property.

Settings form pattern

A common layout pairs a description on the left with a label-free ToggleSwitch on the right:

<StackPanel Spacing="16">
<Grid ColumnDefinitions="*,Auto">
<StackPanel>
<TextBlock Text="Auto-save" FontWeight="SemiBold" />
<TextBlock Text="Save changes automatically"
Foreground="Gray" FontSize="12" />
</StackPanel>
<ToggleSwitch Grid.Column="1" IsChecked="{Binding AutoSave}"
OnContent="" OffContent="" />
</Grid>

<Grid ColumnDefinitions="*,Auto">
<StackPanel>
<TextBlock Text="Spell check" FontWeight="SemiBold" />
<TextBlock Text="Check spelling as you type"
Foreground="Gray" FontSize="12" />
</StackPanel>
<ToggleSwitch Grid.Column="1" IsChecked="{Binding SpellCheck}"
OnContent="" OffContent="" />
</Grid>
</StackPanel>

Setting OnContent and OffContent to empty strings removes the redundant labels because the TextBlock elements already describe each setting.

Choosing between ToggleSwitch and CheckBox

ConsiderationToggleSwitchCheckBox
Visual styleSliding toggleCheck mark
Best suited forSettings, instant on/off statesForm fields, multi-select lists
Three-state supportNoYes (via IsThreeState)
Platform feelMobile and touch friendlyTraditional desktop

Choose ToggleSwitch when the change takes effect immediately. Choose CheckBox when the user must confirm or submit a form before the change is applied.

See also