Skip to content

Commit

Permalink
Add repro sample (xamarin#15647)
Browse files Browse the repository at this point in the history
  • Loading branch information
heikow10 committed Jan 14, 2023
1 parent 33dd32a commit 8eda99e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.ObjectModel;
using System;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.ManualReview)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 15647, "[Bug] Android ListView SelectedItem highlighting", PlatformAffected.Android)]
public class Issue15647 : TestContentPage
{
protected override void Init()
{
ViewModelIssue15647 viewModelIssue15647 = new ViewModelIssue15647();

Label testInstructionsLabel = new Label()
{
HorizontalTextAlignment = TextAlignment.Center,
Padding = new Thickness(3.0),
Text = "Click on the buttons to select the first or second item of the ListView." + Environment.NewLine +
"The correct item has to be marked as selected so that this test is successful.",
};

DataTemplate itemDataTemplate = new DataTemplate(() =>
{
Label itemLabel = new Label();
itemLabel.SetBinding(Label.TextProperty, ".");
return new ViewCell()
{
View = itemLabel,
};
});
ListView itemsListView = new ListView()
{
// Header = "Header",
ItemTemplate = itemDataTemplate,
};
itemsListView.SetBinding(ListView.ItemsSourceProperty, nameof(ViewModelIssue15647.Items));

Button selectFirstItemButton = new Button()
{
Text = "Select first item",
};
selectFirstItemButton.Clicked += (_, __) =>
{
Console.WriteLine(itemsListView.SelectedItem);
itemsListView.SelectedItem = viewModelIssue15647.Items[0];
Console.WriteLine(itemsListView.SelectedItem);
};

Button selectSecondItemButton = new Button()
{
Text = "Select second item",
};
selectSecondItemButton.Clicked += (_, __) =>
{
Console.WriteLine(itemsListView.SelectedItem);
itemsListView.SelectedItem = viewModelIssue15647.Items[1];
Console.WriteLine(itemsListView.SelectedItem);
};

Content = new StackLayout()
{
Children = { testInstructionsLabel, selectFirstItemButton, selectSecondItemButton, itemsListView },
};

BindingContext = viewModelIssue15647;
}
}

[Preserve(AllMembers = true)]
public class ViewModelIssue15647
{
public ViewModelIssue15647()
{
Items = new ObservableCollection<string>() { "first item", "second item" };
}

public ObservableCollection<string> Items { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue15305.xaml.cs">
<DependentUpon>Issue15305.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue15647.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\MyCollectionView.xaml.cs">
<DependentUpon>MyCollectionView.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down

0 comments on commit 8eda99e

Please sign in to comment.