summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-19 06:49:13 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-04-19 06:49:13 (GMT)
commitcae3b1a53aa1108cd2ffc07d368b633b52e7d8de (patch)
treee6c17ff6f42c5a5b879521214a3697ef6f19bf22 /Xamarin.Forms.Platform.WinRT
parent5f762bdc25d7d38ce751d33baa1072868ed8061d (diff)
downloadxamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.zip
xamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.tar.gz
xamarin-forms-cae3b1a53aa1108cd2ffc07d368b633b52e7d8de.tar.bz2
[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
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-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 d623687..7c4acfb 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 f02abe3..1a9fa76 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();