using System; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_SwitchRenderer))] public class Switch : View, IElementConfiguration { public static readonly BindableProperty IsToggledProperty = BindableProperty.Create("IsToggled", typeof(bool), typeof(Switch), false, propertyChanged: (bindable, oldValue, newValue) => { EventHandler eh = ((Switch)bindable).Toggled; if (eh != null) eh(bindable, new ToggledEventArgs((bool)newValue)); }, defaultBindingMode: BindingMode.TwoWay); readonly Lazy> _platformConfigurationRegistry; public Switch() { _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); } public bool IsToggled { get { return (bool)GetValue(IsToggledProperty); } set { SetValue(IsToggledProperty, value); } } public event EventHandler Toggled; public IPlatformElementConfiguration On() where T : IConfigPlatform { return _platformConfigurationRegistry.Value.On(); } } }