summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-08-02 19:28:36 -0500
committerJason Smith <jason.smith@xamarin.com>2016-08-02 17:28:36 -0700
commita0611515e4bf9bb98b149047202ab27a032f259b (patch)
treed6358c1418b7ccc3388231a4b1ae2979e8d62f50
parentd5ad18b3e9947157ab073eb0e5c0a30e7f039c62 (diff)
downloadxamarin-forms-a0611515e4bf9bb98b149047202ab27a032f259b.tar.gz
xamarin-forms-a0611515e4bf9bb98b149047202ab27a032f259b.tar.bz2
xamarin-forms-a0611515e4bf9bb98b149047202ab27a032f259b.zip
[UWP/8.1] ListView respects keyboard selection (#182)
The ListViewRenderer's OnControlSelectionChanged would fire when using the keyboard to change the selection of a ListView, but the Element's SelectedItem value was not being set due to it normally being tracked via tap/click.
-rw-r--r--Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs35
1 files changed, 13 insertions, 22 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
index 5a93eb10..2cd8562c 100644
--- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs
@@ -79,11 +79,8 @@ namespace Xamarin.Forms.Platform.WinRT
// We also want to watch for the Enter key being pressed for selection
List.KeyUp += OnKeyPressed;
-
- if (ShouldCustomHighlight)
- {
- List.SelectionChanged += OnControlSelectionChanged;
- }
+
+ List.SelectionChanged += OnControlSelectionChanged;
List.SetBinding(ItemsControl.ItemsSourceProperty, "");
}
@@ -146,10 +143,7 @@ namespace Xamarin.Forms.Platform.WinRT
List.Tapped -= ListOnTapped;
List.KeyUp -= OnKeyPressed;
- if (ShouldCustomHighlight)
- {
- List.SelectionChanged -= OnControlSelectionChanged;
- }
+ List.SelectionChanged -= OnControlSelectionChanged;
List.DataContext = null;
List = null;
@@ -204,18 +198,6 @@ namespace Xamarin.Forms.Platform.WinRT
ContentControl _headerControl;
readonly List<BrushedElement> _highlightedElements = new List<BrushedElement>();
- bool ShouldCustomHighlight
- {
- get
- {
-#if WINDOWS_UWP
- return false;
-#else
- return Device.Idiom == TargetIdiom.Phone;
-#endif
- }
- }
-
void ClearSizeEstimate()
{
Element.ClearValue(CellControl.MeasuredEstimateProperty);
@@ -543,7 +525,8 @@ namespace Xamarin.Forms.Platform.WinRT
if (cell == null)
return;
- if (ShouldCustomHighlight)
+#if !WINDOWS_UWP
+ if (Device.Idiom == TargetIdiom.Phone)
{
FrameworkElement element = FindElement(cell);
if (element != null)
@@ -551,6 +534,14 @@ namespace Xamarin.Forms.Platform.WinRT
SetSelectedVisual(element);
}
}
+#endif
+
+ // This is used for respecting ListView selection changes via keyboard, as the SelectedItem
+ // value is otherwise not set.
+ if (Element.SelectedItem != List.SelectedItem)
+ {
+ ((IElementController)Element).SetValueFromRenderer(ListView.SelectedItemProperty, List.SelectedItem);
+ }
}
FrameworkElement FindElement(object cell)