summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorSamantha Houts <samantha.houts@xamarin.com>2017-09-26 10:34:35 -0700
committerSamantha Houts <samantha.houts@xamarin.com>2017-09-26 10:34:35 -0700
commit783ecfcde057f4d8920058410bcba3d1d353808e (patch)
tree0bee2840699a96d967f78396ed5a93918c993199 /Xamarin.Forms.Platform.WinRT
parent78b8be17aa0f428df9d1440e0536027574741a2e (diff)
downloadxamarin-forms-783ecfcde057f4d8920058410bcba3d1d353808e.tar.gz
xamarin-forms-783ecfcde057f4d8920058410bcba3d1d353808e.tar.bz2
xamarin-forms-783ecfcde057f4d8920058410bcba3d1d353808e.zip
Revert "[UWP] Use ItemClick to re-enable use of enter key for selection on ListView (#1133)"
This reverts commit d1bf93be200b3d3c48d0d292bf455f444485d8f9.
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs48
1 files changed, 38 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
index 33525bc1..0fb5af80 100644
--- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
@@ -72,8 +72,10 @@ namespace Xamarin.Forms.Platform.WinRT
GroupStyleSelector = (GroupStyleSelector)WApp.Current.Resources["ListViewGroupSelector"]
};
- List.IsItemClickEnabled = true;
- List.ItemClick += OnListItemClicked;
+ // In order to support tapping on elements within a list item, we handle
+ // ListView.Tapped (which can be handled by child elements in the list items
+ // and prevented from bubbling up) rather than ListView.ItemClick
+ List.Tapped += ListOnTapped;
List.SelectionChanged += OnControlSelectionChanged;
@@ -135,7 +137,8 @@ namespace Xamarin.Forms.Platform.WinRT
{
if (List != null)
{
- List.ItemClick -= OnListItemClicked;
+ List.Tapped -= ListOnTapped;
+
List.SelectionChanged -= OnControlSelectionChanged;
List.DataContext = null;
@@ -434,6 +437,32 @@ namespace Xamarin.Forms.Platform.WinRT
List.SelectedIndex = index;
}
+ void ListOnTapped(object sender, TappedRoutedEventArgs args)
+ {
+ var orig = args.OriginalSource as DependencyObject;
+ int index = -1;
+
+ // Work our way up the tree until we find the actual list item
+ // the user tapped on
+ while (orig != null && orig != List)
+ {
+ var lv = orig as ListViewItem;
+
+ if (lv != null)
+ {
+ index = TemplatedItemsView.TemplatedItems.GetGlobalIndexOfItem(lv.Content);
+ break;
+ }
+
+ orig = VisualTreeHelper.GetParent(orig);
+ }
+
+ if (index > -1)
+ {
+ OnListItemClicked(index);
+ }
+ }
+
void OnListItemClicked(int index)
{
#if !WINDOWS_UWP
@@ -475,12 +504,6 @@ namespace Xamarin.Forms.Platform.WinRT
#endif
}
- void OnListItemClicked(object sender, ItemClickEventArgs e)
- {
- if (e.ClickedItem != null)
- OnListItemClicked(((WListView)e.OriginalSource).Items.IndexOf(e.ClickedItem));
- }
-
void OnControlSelectionChanged(object sender, SelectionChangedEventArgs e)
{
RestorePreviousSelectedVisual();
@@ -510,8 +533,13 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
#endif
+
+ // A11y: Tapped event will not be routed when Narrator is active, so we need to handle it here.
+ // Also handles keyboard selection.
+ // Default UWP behavior is that items are selected when you navigate to them via the arrow keys
+ // and deselected with the space bar, so this will remain the same.
if (Element.SelectedItem != List.SelectedItem)
- ((IElementController)Element).SetValueFromRenderer(ListView.SelectedItemProperty, List.SelectedItem);
+ OnListItemClicked(List.SelectedIndex);
}
FrameworkElement FindElement(object cell)