Xamarin.Forms Guides | Samples

Xamarin.Forms.Switch Class

A View control that provides a toggled value.

See Also: Switch


public class Switch : View, IElementConfiguration<Switch>


The following example describes a basic use.

C# Example

using System;
using Xamarin.Forms;

namespace FormsGallery
    class SwitchDemoPage : ContentPage
        Label label;

        public SwitchDemoPage()
            Label header = new Label
                Text = "Switch",
                FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center

            Switch switcher = new Switch
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand
            switcher.Toggled += switcher_Toggled;

            label = new Label
                Text = "Switch is now False",
                FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand

            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            // Build the page.
            this.Content = new StackLayout
                Children =

        void switcher_Toggled(object sender, ToggledEventArgs e)
            label.Text = String.Format("Switch is now {0}", e.Value);

XAML for Xamarin.Forms supports the following properties for the Switch class:


true or false, to indicate whether the switch has been toggled.


The name of an event handler. Note that this tag must appear below IsToggled.


Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions:,,,,,,

The members of Xamarin.Forms.Switch are listed below.

See Also: View

Public Constructors

Creates a new Switch element with default values.

Public Fields

static readonly
IsToggledPropertyBindableProperty. Backing store for the Switch.IsToggled property.

Public Properties

IsToggledBoolean. Gets or sets a Boolean value that indicates whether this Switch element is toggled.

Public Methods

On<T>() : IPlatformElementConfiguration<T, Switch>
Returns the platform-specific instance of this Switch, on which a platform-specific method may be called.

Public Events

ToggledEvent that is raised when this Switch is toggled.