Xamarin.Forms Guides | Samples

Xamarin.Forms.SwitchCell Class

A Cell with a label and an on/off switch.

See Also: SwitchCell

Syntax

public class SwitchCell : Cell

Remarks

The following example shows a basic use.

C# Example

using System;
using Xamarin.Forms;

namespace FormsGallery
{
    class SwitchCellDemoPage : ContentPage
    {
        public SwitchCellDemoPage()
        {
            Label header = new Label
            {
                Text = "SwitchCell",
                FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };

            TableView tableView = new TableView
            {
                Intent = TableIntent.Form,
                Root = new TableRoot
                {
                    new TableSection
                    {
                        new SwitchCell
                        {
                            Text = "SwitchCell:"
                        }
                    }
                }
            };

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

            // Build the page.
            this.Content = new StackLayout
            {
                Children =
                {
                    header,
                    tableView
                }
            };
        }
    }
}

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

PropertyValue
On

true or false, to indicate whether the switch cell is in the "on" position.

OnChanged

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

Text

Text that represents the title of the switch cell.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

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

See Also: Cell

Public Constructors

Initializes a new instance of the SwitchCell class.

Public Fields

static readonly
OnPropertyBindableProperty. Identifies the SwitchCell.On bindable property.
static readonly
TextPropertyBindableProperty. Identifies the Text bindable property.

Public Properties

OnBoolean. Gets or sets the state of the switch. This is a bindable property.
TextString. Gets or sets the text displayed next to the switch. This is a bindable property.

Public Events

OnChangedTriggered when the switch has changed value.