From ed517a3027fb8a273b1f4226622cf88378091cd9 Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Thu, 16 Jun 2016 12:17:18 -0400 Subject: [PATCH] [UWP] Escape key returns ActionSheet result (#208) When awaiting a DisplayActionSheet in UWP, pressing the escape key with the ActionSheet open would dismiss the dialog but not return a result. --- .../Bugzilla40998.cs | 41 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + Xamarin.Forms.Platform.WinRT/Platform.cs | 15 ++++++++ 3 files changed, 57 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40998.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40998.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40998.cs new file mode 100644 index 0000000..28288a4 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40998.cs @@ -0,0 +1,41 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 40998, "[UWP] Pressing escape with an awaited DisplayActionSheet doesn't return a result", PlatformAffected.WinRT)] + public class Bugzilla40998 : TestContentPage + { + protected override void Init() + { + var resultLabel = new Label + { + Text = "ActionSheet Result - use the ActionSheet to show the result" + }; + Content = new StackLayout + { + Children = + { + resultLabel, + new Button + { + Text = "Click to display ActionSheet", + Command = new Command(async () => + { + var result = await DisplayActionSheet("Test ActionSheet", "Cancel", "Destroy", new string[] { "Test Button" }); + resultLabel.Text = result; + }) + } + } + }; + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 00fad87..8d7f9a7 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -105,6 +105,7 @@ + diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs index 6c158a0..311186b 100644 --- a/Xamarin.Forms.Platform.WinRT/Platform.cs +++ b/Xamarin.Forms.Platform.WinRT/Platform.cs @@ -13,7 +13,9 @@ using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Animation; #if WINDOWS_UWP +using Windows.Foundation; using Windows.Foundation.Metadata; +using Windows.UI.Core; using Windows.UI.ViewManagement; #endif @@ -591,6 +593,17 @@ namespace Xamarin.Forms.Platform.WinRT options.SetResult((string)e.ClickedItem); }; + TypedEventHandler onEscapeButtonPressed = delegate(CoreWindow window, CharacterReceivedEventArgs args) + { + if (args.KeyCode == 27) + { + dialog.Hide(); + options.SetResult(ContentDialogResult.None.ToString()); + } + }; + + Window.Current.CoreWindow.CharacterReceived += onEscapeButtonPressed; + _actionSheetOptions = options; if (options.Cancel != null) @@ -604,6 +617,8 @@ namespace Xamarin.Forms.Platform.WinRT options.SetResult(options.Cancel); else if (result == ContentDialogResult.Primary) options.SetResult(options.Destruction); + + Window.Current.CoreWindow.CharacterReceived -= onEscapeButtonPressed; } #else void OnPageActionSheet(Page sender, ActionSheetArguments options) -- 2.7.4