[Win 8.1] Initial ListView selection not shown (#174)
authorPaul DiPietro <pauldipietro@users.noreply.github.com>
Wed, 8 Jun 2016 17:38:08 +0000 (13:38 -0400)
committerJason Smith <jason.smith@xamarin.com>
Wed, 8 Jun 2016 17:38:08 +0000 (10:38 -0700)
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.

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41078.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.WinRT/ListViewRenderer.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 (file)
index 0000000..0c91533
--- /dev/null
@@ -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<int> { 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
+                               }
+                       };
+               }
+       }
+}
index 2a8db8f..991270b 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40185.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40333.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31806.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
index bbd101f..d47299a 100644 (file)
@@ -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();