From a64fef6a150d548f0311af48658c2c52971ac66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Rocha?= Date: Fri, 17 Sep 2021 01:05:04 -0700 Subject: [PATCH] [macOS] Fix RadioButton activated behaviour (#14139) * Respond to Activated event * Set initial control state based on element state * Revert "Set initial control state based on element state" This reverts commit 1bd1238b714d291fa9b416a08085abc200289dc1. --- .../Renderers/RadioButtonRenderer.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/RadioButtonRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/RadioButtonRenderer.cs index 35d0c91786c..07708b12410 100644 --- a/Xamarin.Forms.Platform.MacOS/Renderers/RadioButtonRenderer.cs +++ b/Xamarin.Forms.Platform.MacOS/Renderers/RadioButtonRenderer.cs @@ -29,6 +29,12 @@ protected override void Dispose(bool disposing) { ObserveStateChange(false); + var formsButton = Control as FormsNSButton; + if (formsButton != null) + { + formsButton.Activated -= HandleActivated; + } + base.Dispose(disposing); } @@ -44,6 +50,8 @@ protected override void OnElementChanged(ElementChangedEventArgs e) btn.SetButtonType(NSButtonType.Radio); SetNativeControl(btn); ObserveStateChange(true); + + btn.Activated += HandleActivated; } UpdateContent(); @@ -156,5 +164,15 @@ void OnStateChanged() Element.IsChecked = Control.State == NSCellStateValue.On; } + + void HandleActivated(object sender, EventArgs args) + { + if (Element == null || sender == null) + { + return; + } + + Element.IsChecked = (sender as FormsNSButton).State == NSCellStateValue.On; + } } }