From 18f071ad19e986b832d0a7b76a72b55d55eed246 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Thu, 1 Aug 2019 13:28:29 +0200 Subject: [PATCH] [UWP] The SelectedItem in a ListView is not highlighted when set while constructing a page (#6973) * Enable selection of an item from constructor * Update ListViewRenderer.cs * Update ListViewRenderer.cs * Update ListViewRenderer.cs --- Xamarin.Forms.Platform.UAP/ListViewRenderer.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Xamarin.Forms.Platform.UAP/ListViewRenderer.cs b/Xamarin.Forms.Platform.UAP/ListViewRenderer.cs index 157af8a..695b8d7 100644 --- a/Xamarin.Forms.Platform.UAP/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/ListViewRenderer.cs @@ -84,9 +84,6 @@ namespace Xamarin.Forms.Platform.UWP ReloadData(); - if (Element.SelectedItem != null) - OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem, TemplatedItemsView.TemplatedItems.GetGlobalIndexOfItem(Element.SelectedItem))); - UpdateGrouping(); UpdateHeader(); UpdateFooter(); @@ -418,6 +415,10 @@ namespace Xamarin.Forms.Platform.UWP else if (Element.SelectionMode == ListViewSelectionMode.Single) { List.SelectionMode = Windows.UI.Xaml.Controls.ListViewSelectionMode.Single; + + // UWP seems to reset the selected item when SelectionMode is set, make sure our items stays selected by doing this call + if (Element.SelectedItem != null) + OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem, TemplatedItemsView.TemplatedItems.GetGlobalIndexOfItem(Element.SelectedItem))); } } @@ -788,4 +789,4 @@ namespace Xamarin.Forms.Platform.UWP } } -} \ No newline at end of file +} -- 2.7.4