From 463e128bd78da55adbc923fede67c2e41e4e3e3c Mon Sep 17 00:00:00 2001 From: MH Rastegari <42671084+mhrastegary77@users.noreply.github.com> Date: Tue, 8 Jun 2021 21:49:09 +0430 Subject: [PATCH 1/2] [macOS] Update Switch renderer #14313 --- .../Renderers/SwitchRenderer.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs index c93007e2d5d..d87fc1ff96f 100644 --- a/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs +++ b/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs @@ -3,7 +3,7 @@ namespace Xamarin.Forms.Platform.MacOS { - public class SwitchRenderer : ViewRenderer + public class SwitchRenderer : ViewRenderer { bool _disposed; @@ -18,12 +18,9 @@ protected override void OnElementChanged(ElementChangedEventArgs e) { if (Control == null) { - SetNativeControl(new NSButton { AllowsMixedState = false, Title = string.Empty }); - - Control.SetButtonType(NSButtonType.Switch); + SetNativeControl(new NSSwitch()); Control.Activated += OnControlActivated; } - UpdateState(); e.NewElement.Toggled += OnElementToggled; } @@ -45,7 +42,7 @@ protected override void Dispose(bool disposing) void OnControlActivated(object sender, EventArgs e) { - ElementController?.SetValueFromRenderer(Switch.IsToggledProperty, Control.State == NSCellStateValue.On); + ElementController?.SetValueFromRenderer(Switch.IsToggledProperty, Control.State == (int)NSCellStateValue.On); } void OnElementToggled(object sender, EventArgs e) @@ -55,7 +52,7 @@ void OnElementToggled(object sender, EventArgs e) void UpdateState() { - Control.State = Element.IsToggled ? NSCellStateValue.On : NSCellStateValue.Off; + Control.State = Element.IsToggled ? (int)NSCellStateValue.On : (int)NSCellStateValue.Off; } } } \ No newline at end of file From 17147e4a42d805b33b0e154d90f177488086c72e Mon Sep 17 00:00:00 2001 From: MH Rastegari <42671084+mhrastegary77@users.noreply.github.com> Date: Tue, 8 Jun 2021 21:49:09 +0430 Subject: [PATCH 2/2] [macOS] Update Switch renderer #14313 --- .../Renderers/SwitchRenderer.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs index c93007e2d5d..d87fc1ff96f 100644 --- a/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs +++ b/Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs @@ -3,7 +3,7 @@ namespace Xamarin.Forms.Platform.MacOS { - public class SwitchRenderer : ViewRenderer + public class SwitchRenderer : ViewRenderer { bool _disposed; @@ -18,12 +18,9 @@ protected override void OnElementChanged(ElementChangedEventArgs e) { if (Control == null) { - SetNativeControl(new NSButton { AllowsMixedState = false, Title = string.Empty }); - - Control.SetButtonType(NSButtonType.Switch); + SetNativeControl(new NSSwitch()); Control.Activated += OnControlActivated; } - UpdateState(); e.NewElement.Toggled += OnElementToggled; } @@ -45,7 +42,7 @@ protected override void Dispose(bool disposing) void OnControlActivated(object sender, EventArgs e) { - ElementController?.SetValueFromRenderer(Switch.IsToggledProperty, Control.State == NSCellStateValue.On); + ElementController?.SetValueFromRenderer(Switch.IsToggledProperty, Control.State == (int)NSCellStateValue.On); } void OnElementToggled(object sender, EventArgs e) @@ -55,7 +52,7 @@ void OnElementToggled(object sender, EventArgs e) void UpdateState() { - Control.State = Element.IsToggled ? NSCellStateValue.On : NSCellStateValue.Off; + Control.State = Element.IsToggled ? (int)NSCellStateValue.On : (int)NSCellStateValue.Off; } } } \ No newline at end of file