Skip to content

Switch

A switch is a visual toggle between two mutually exclusive states—on and off. The switch is an instance of the UISwitch class.

Switch

Configuring switch properties

The following figure show the properties of the switch that can be configured from the story board:

Switch properties

Handle changed event

We can wire up the ValueChanged event from the story board as show below:

SwitchValue Changed Event

and add the method in the view controller file as follows:

1
2
3
4
partial void HandleRingChanged(UISwitch sender)
{
    Debug.WriteLine(sender.On);
}

The On property will be true or false as you toggle the switch.

The event could also be wired in code as follows:

1
2
3
ringSwitch.ValueChanged += (sender, e) => {
    Debug.WriteLine(ringSwitch.On);
};

ringSwitch variable name is setup in the story board Properties window.