Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[8.1/UWP] ListView allows selection with enter key (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldipietro authored and Jason Smith committed Jul 19, 2016
1 parent 28d9e8a commit a80d5c0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -76,6 +77,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
// 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;
Expand Down Expand Up @@ -140,6 +144,7 @@ protected override void Dispose(bool disposing)
if (List != null)
{
List.Tapped -= ListOnTapped;
List.KeyUp -= OnKeyPressed;

if (ShouldCustomHighlight)
{
Expand Down Expand Up @@ -521,6 +526,12 @@ void OnListItemClicked(int index)
#endif
}

void OnKeyPressed(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Enter)
OnListItemClicked(List.SelectedIndex);
}

void OnControlSelectionChanged(object sender, SelectionChangedEventArgs e)
{
RestorePreviousSelectedVisual();
Expand Down

0 comments on commit a80d5c0

Please sign in to comment.