From ed517a3027fb8a273b1f4226622cf88378091cd9 Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Thu, 16 Jun 2016 12:17:18 -0400 Subject: [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. --- Xamarin.Forms.Platform.WinRT/Platform.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Xamarin.Forms.Platform.WinRT') diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs index 6c158a05..311186b2 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) -- cgit v1.2.3