[UWP] Set ListView SelectedItem when constructing page (#1357)

This commit is contained in:
Paul DiPietro 2017-12-21 14:32:48 -05:00 коммит произвёл Rui Marinho
Родитель aec4175c2d
Коммит 640e35526b
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,37 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.ObjectModel;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1356, "[UWP] A selected item in a ListView is not highlighted when constructing the page", PlatformAffected.UWP)]
public class Issue1356 : TestContentPage
{
ObservableCollection<string> items = new ObservableCollection<string>() { "A", "B", "C" };
ListView listView;
protected override void Init()
{
listView = new ListView
{
ItemsSource = items
};
Content = new StackLayout
{
Children =
{
listView,
new Label { Text = "Item 'B' should be highlighted when loading this page" }
}
};
listView.SelectedItem = items[1];
}
}
}

Просмотреть файл

@ -256,6 +256,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue1024.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1025.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1026.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1356.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1691.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2983.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2963.cs" />

Просмотреть файл

@ -64,6 +64,9 @@ namespace Xamarin.Forms.Platform.UWP
// 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 (Element.SelectedItem != null)
OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem));
UpdateGrouping();
UpdateHeader();
UpdateFooter();