From a80d5c0de704837588138966be1b38a89ed24be9 Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Mon, 18 Jul 2016 22:05:08 -0500 Subject: [8.1/UWP] ListView allows selection with enter key (#241) --- Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs') diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs index d6ec7038..5a93eb10 100644 --- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Windows.Foundation; +using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; @@ -76,6 +77,9 @@ namespace Xamarin.Forms.Platform.WinRT // and prevented from bubbling up) rather than ListView.ItemClick List.Tapped += ListOnTapped; + // We also want to watch for the Enter key being pressed for selection + List.KeyUp += OnKeyPressed; + if (ShouldCustomHighlight) { List.SelectionChanged += OnControlSelectionChanged; @@ -140,6 +144,7 @@ namespace Xamarin.Forms.Platform.WinRT if (List != null) { List.Tapped -= ListOnTapped; + List.KeyUp -= OnKeyPressed; if (ShouldCustomHighlight) { @@ -521,6 +526,12 @@ namespace Xamarin.Forms.Platform.WinRT #endif } + void OnKeyPressed(object sender, KeyRoutedEventArgs e) + { + if (e.Key == VirtualKey.Enter) + OnListItemClicked(List.SelectedIndex); + } + void OnControlSelectionChanged(object sender, SelectionChangedEventArgs e) { RestorePreviousSelectedVisual(); -- cgit v1.2.3