summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-19 00:49:13 -0600
committerJason Smith <jason.smith@xamarin.com>2016-04-18 23:49:13 -0700
commitcae3b1a53aa1108cd2ffc07d368b633b52e7d8de (patch)
treee6c17ff6f42c5a5b879521214a3697ef6f19bf22
parent5f762bdc25d7d38ce751d33baa1072868ed8061d (diff)
downloadxamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.tar.gz
xamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.tar.bz2
xamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.zip
[UWP] Unhook Entry and Editor event handlers during Dispose (#114)
* [UWP] Null-check Element in native event handlers for Entry * Unhook event handlers in Dispose * Prevent race condition using Control in event handlers
-rw-r--r--Xamarin.Forms.Platform.WinRT/EditorRenderer.cs19
-rw-r--r--Xamarin.Forms.Platform.WinRT/EntryRenderer.cs16
2 files changed, 29 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/EditorRenderer.cs b/Xamarin.Forms.Platform.WinRT/EditorRenderer.cs
index d6236871..7c4acfba 100644
--- a/Xamarin.Forms.Platform.WinRT/EditorRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/EditorRenderer.cs
@@ -22,10 +22,10 @@ namespace Xamarin.Forms.Platform.WinRT
{
var textBox = new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap };
+ SetNativeControl(textBox);
+
textBox.TextChanged += OnNativeTextChanged;
textBox.LostFocus += OnLostFocus;
-
- SetNativeControl(textBox);
}
UpdateText();
@@ -37,6 +37,17 @@ namespace Xamarin.Forms.Platform.WinRT
base.OnElementChanged(e);
}
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && Control != null)
+ {
+ Control.TextChanged -= OnNativeTextChanged;
+ Control.LostFocus -= OnLostFocus;
+ }
+
+ base.Dispose(disposing);
+ }
+
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Editor.TextColorProperty.PropertyName)
@@ -65,12 +76,12 @@ namespace Xamarin.Forms.Platform.WinRT
void OnLostFocus(object sender, RoutedEventArgs e)
{
- Element?.SendCompleted();
+ Element.SendCompleted();
}
void OnNativeTextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs args)
{
- Element?.SetValueCore(Editor.TextProperty, Control.Text);
+ Element.SetValueCore(Editor.TextProperty, Control.Text);
}
void UpdateFont()
diff --git a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
index f02abe3c..1a9fa767 100644
--- a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs
@@ -27,10 +27,11 @@ namespace Xamarin.Forms.Platform.WinRT
if (Control == null)
{
var textBox = new FormsTextBox { Style = Windows.UI.Xaml.Application.Current.Resources["FormsTextBoxStyle"] as Windows.UI.Xaml.Style };
+
+ SetNativeControl(textBox);
textBox.TextChanged += OnNativeTextChanged;
textBox.KeyUp += TextBoxOnKeyUp;
- SetNativeControl(textBox);
}
UpdateIsPassword();
@@ -44,6 +45,17 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && Control != null)
+ {
+ Control.TextChanged -= OnNativeTextChanged;
+ Control.KeyUp -= TextBoxOnKeyUp;
+ }
+
+ base.Dispose(disposing);
+ }
+
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
@@ -107,7 +119,7 @@ namespace Xamarin.Forms.Platform.WinRT
void TextBoxOnKeyUp(object sender, KeyRoutedEventArgs args)
{
- if (args.Key != VirtualKey.Enter)
+ if (args?.Key != VirtualKey.Enter)
return;
Element.SendCompleted();