Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[macOS] Update Switch renderer (#14334) fixes #14313
Browse files Browse the repository at this point in the history
* [macOS] Update Switch renderer #14313

* [macOS] Update Switch renderer #14313
  • Loading branch information
mhrastegari committed Jul 7, 2021
1 parent 81fc2d4 commit 7b0ccc0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Xamarin.Forms.Platform.MacOS/Renderers/SwitchRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Xamarin.Forms.Platform.MacOS
{
public class SwitchRenderer : ViewRenderer<Switch, NSButton>
public class SwitchRenderer : ViewRenderer<Switch, NSSwitch>
{
bool _disposed;

Expand All @@ -18,12 +18,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<Switch> 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;
}
Expand All @@ -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)
Expand All @@ -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;
}
}
}

0 comments on commit 7b0ccc0

Please sign in to comment.