From ce0238846a5aa9436d2d7a79682688511473f595 Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Wed, 8 Jun 2016 13:38:08 -0400 Subject: [PATCH] [Win 8.1] Initial ListView selection not shown (#174) On Windows 8.1, when initially setting a ListView's SelectedItem, the item in question would not have any visual indication that it was selected when first showing (a background color for the cell). Subsequent selections would work as expected. --- .../Bugzilla41078.cs | 36 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../ListViewRenderer.cs | 6 ++++ 3 files changed, 43 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41078.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41078.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41078.cs new file mode 100644 index 000000000..0c9153312 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41078.cs @@ -0,0 +1,36 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Collections.Generic; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 41078, "[Win 8.1] ListView not visually setting the initial SelectedItem upon creation", PlatformAffected.WinRT)] + public class Bugzilla41078 : TestContentPage + { + protected override void Init() + { + var list = new List { 1, 2, 3 }; + var listView = new ListView + { + ItemsSource = list, + SelectedItem = list[1] + }; + Content = new StackLayout + { + Children = + { + new Label { Text = "The '2' cell should have a background color indicating it is selected" }, + listView + } + }; + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 2a8db8fb2..991270b66 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -104,6 +104,7 @@ + diff --git a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs index bbd101fa1..d47299a47 100644 --- a/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ListViewRenderer.cs @@ -83,6 +83,12 @@ namespace Xamarin.Forms.Platform.WinRT // WinRT throws an exception if you set ItemsSource directly to a CVS, so bind it. List.DataContext = new CollectionViewSource { Source = Element.ItemsSource, IsSourceGrouped = Element.IsGroupingEnabled }; +#if !WINDOWS_UWP + var selected = Element.SelectedItem; + if (selected != null) + OnElementItemSelected(null, new SelectedItemChangedEventArgs(selected)); +#endif + UpdateGrouping(); UpdateHeader(); UpdateFooter();