Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <dolouis@microsoft.com>2020-04-28 19:23:35 +0300
committerGitHub <noreply@github.com>2020-04-28 19:23:35 +0300
commitd3ec80e8de373f60df70d45f717c0ed1bf875dc6 (patch)
treee801f7362b58353c8cbe049afecf875fb0dfc3ab
parent8ddbe00c8a53af7d1fa31cbb719a3fcc8471d935 (diff)
Fix NRE when SelectionChanged is firing on a null object. (#717)
* Fix NRE when SelectionChanged is firing on a disposed object. * Don't forget to hook the SelectionChange up again, after removing everything. * During control re-use, SelectedValue might be null. So check for that.
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs19
1 files changed, 14 insertions, 5 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs
index 2c80314..f402bf7 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs
@@ -44,10 +44,11 @@ namespace Xamarin.PropertyEditing.Mac
} else {
RequireComboBox ();
- this.comboBox.RemoveAll ();
+ UnhookSelectionChangeAndClearItems ();
foreach (var item in ViewModel.PossibleValues) {
this.comboBox.Add (new NSString (item));
}
+ this.comboBox.SelectionChanged += ComboBox_SelectionChanged;
}
base.OnViewModelChanged (oldModel);
@@ -134,9 +135,7 @@ namespace Xamarin.PropertyEditing.Mac
{
if (this.comboBox == null)
return;
-
- this.comboBox.SelectionChanged -= ComboBox_SelectionChanged;
- this.comboBox.RemoveAll ();
+ UnhookSelectionChangeAndClearItems ();
this.comboBox.RemoveFromSuperview ();
this.comboBox.Dispose ();
this.comboBox = null;
@@ -185,9 +184,19 @@ namespace Xamarin.PropertyEditing.Mac
private void ComboBox_SelectionChanged (object sender, EventArgs e)
{
- if (ViewModel != null && this.comboBox != null) {
+ if (ViewModel != null
+ && this.comboBox != null
+ && this.comboBox.SelectedValue != null) {
ViewModel.ValueName = this.comboBox.SelectedValue.ToString ();
}
}
+
+ private void UnhookSelectionChangeAndClearItems ()
+ {
+ if (this.comboBox != null) {
+ this.comboBox.SelectionChanged -= ComboBox_SelectionChanged;
+ this.comboBox.RemoveAll ();
+ }
+ }
}
}