diff options
author | CartBlanche <savagesoftware@gmail.com> | 2020-02-27 13:06:37 +0300 |
---|---|---|
committer | Dominique Louis <savagesoftware@gmail.com> | 2020-02-27 16:07:05 +0300 |
commit | b9cc9e83798d73d56bde64f4f89da85b24e19cb9 (patch) | |
tree | 469c372890c0f5449ad8e3a94716e2ef1257bd5a /Xamarin.PropertyEditing.Mac/Controls | |
parent | 9f49c41e35ad1161582bc29ddc0d65e9278edfb1 (diff) |
[Mac] Ensure events are unsubscribed when controls removed and additional ViewModel null check for both controls.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index 4cac9a1..2c80314 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -85,10 +85,12 @@ namespace Xamarin.PropertyEditing.Mac if (this.popupButton == null) return; + this.popupButton.Activated -= PopupButton_Activated; this.popupButton.RemoveFromSuperview (); this.popupButton.Dispose (); this.popupButton = null; + this.popupButtonList.RemoveAllItems (); this.popupButtonList.Dispose (); this.popupButtonList = null; } @@ -114,7 +116,7 @@ namespace Xamarin.PropertyEditing.Mac this.popupButtonList = new NSMenu (); this.popupButton.Menu = this.popupButtonList; - this.popupButton.Activated += (o, e) => ViewModel.ValueName = (o as NSPopUpButton).Title; + this.popupButton.Activated += PopupButton_Activated; AddSubview (this.popupButton); @@ -133,6 +135,8 @@ namespace Xamarin.PropertyEditing.Mac if (this.comboBox == null) return; + this.comboBox.SelectionChanged -= ComboBox_SelectionChanged; + this.comboBox.RemoveAll (); this.comboBox.RemoveFromSuperview (); this.comboBox.Dispose (); this.comboBox = null; @@ -158,9 +162,7 @@ namespace Xamarin.PropertyEditing.Mac StringValue = String.Empty, }; - this.comboBox.SelectionChanged += (sender, e) => { - ViewModel.ValueName = this.comboBox.SelectedValue.ToString (); - }; + this.comboBox.SelectionChanged += ComboBox_SelectionChanged; AddSubview (this.comboBox); @@ -173,5 +175,19 @@ namespace Xamarin.PropertyEditing.Mac this.firstKeyView = this.comboBox; this.lastKeyView = this.comboBox; } + + private void PopupButton_Activated (object sender, EventArgs e) + { + if (ViewModel != null && sender is NSPopUpButton popUpButton) { + ViewModel.ValueName = popUpButton.Title; + } + } + + private void ComboBox_SelectionChanged (object sender, EventArgs e) + { + if (ViewModel != null && this.comboBox != null) { + ViewModel.ValueName = this.comboBox.SelectedValue.ToString (); + } + } } } |