Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ int IndexInGroup(object item, object group)
{
return index;
}

index++;
}
return -1;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22320.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 22320, "CollectionView does not highlight selected grouped items correctly", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue22320 : ContentPage
{
public Issue22320()
{
var layout = new StackLayout();
var bindingContext = new Issue22320ViewModel();
var collectionView = new CollectionView();
collectionView.BindingContext = bindingContext;
collectionView.IsGrouped = true;
collectionView.AutomationId = "CollectionView";
collectionView.SelectionMode = SelectionMode.Single;

collectionView.ItemTemplate = new DataTemplate(() =>
{
var border = new Border
{
HeightRequest = 20
};

var label = new Label();
label.SetBinding(Label.TextProperty, ".");

border.Content = label;

return border;
});

collectionView.GroupHeaderTemplate = new DataTemplate(() =>
{
var border = new Border
{
Background = Colors.LightGrey,
HeightRequest = 20
};

var label = new Label();
label.SetBinding(Label.TextProperty, "Key");

border.Content = label;

return border;
});

// Set the ItemsSource binding
collectionView.SetBinding(CollectionView.ItemsSourceProperty, "Items");
layout.Children.Add(collectionView);

Content = layout;
}
}

public class Issue22320ItemGroup : IEnumerable<string>
{
private readonly string _key;
private readonly IEnumerable<string> _items;

public Issue22320ItemGroup(string key, IEnumerable<string> items)
{
_key = key;
_items = items;
}

public string Key => _key;

public IEnumerator<string> GetEnumerator() => _items.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

public class Issue22320ViewModel
{
public Issue22320ViewModel()
{

Items.Add(new Issue22320ItemGroup("Vegetables", new[] { "Carrot", "Broccoli", "Spinach", "Potato", "Tomato" }));
Items.Add(new Issue22320ItemGroup("Fruits", new[] { "Apple", "Banana", "Orange", "Grapes", "Mango" }));
}

public ObservableCollection<Issue22320ItemGroup> Items { get; } = new();
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue22320 : _IssuesUITest
{
public Issue22320(TestDevice device) : base(device)
{
}

public override string Issue => "CollectionView does not highlight selected grouped items correctly";

[Test]
[Category(UITestCategories.CollectionView)]
public void SelectionShouldNotMovedToTopWithGroupedCollection()
{
App.WaitForElement("CollectionView");
App.Tap("Grapes");
App.Tap("Potato");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.