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 @@ -782,7 +782,10 @@ UniformGridLayout CreateGridView(GridItemsLayout gridItemsLayout)
bool noTemplate = ItemsView.ItemTemplate is null;
bool isMeasureAllItems = ItemsView is CollectionView cv && cv.ItemSizingStrategy == ItemSizingStrategy.MeasureAllItems;

layout.ItemsStretch = (noTemplate && isMeasureAllItems)
bool isHorizontalLayout = gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal;
// Uniform stretching gives an untemplated horizontal grid enough width to scroll,
// but on a vertical grid it also inflates row height and creates large blank gaps.
layout.ItemsStretch = (isHorizontalLayout && noTemplate && isMeasureAllItems)
? UniformGridLayoutItemsStretch.Uniform
: UniformGridLayoutItemsStretch.Fill;
layout.ItemsJustification = UniformGridLayoutItemsJustification.Start;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue38059.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 38059, "CollectionView VerticalGrid has excessive spacing without an ItemTemplate", PlatformAffected.UWP)]
public class Issue38059 : ContentPage
{
public Issue38059()
{
var instructions = new Label
{
AutomationId = "InstructionsLabel",
Text = "The test passes if the monkey names are displayed in a compact two-column grid."
};

var collectionView = new CollectionView
{
AutomationId = "MonkeyCollectionView",
ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems,
ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical),
ItemsSource = new[]
{
"Baboon",
"Capuchin Monkey",
"Blue Monkey",
"Squirrel Monkey",
"Golden Lion Tamarin",
"Howler Monkey",
"Japanese Macaque",
"Mandrill",
"Proboscis Monkey",
"Red-shanked Douc",
"Gray-shanked Douc",
"Golden Snub-nosed Monkey",
"Black Snub-nosed Monkey",
"Tonkin Snub-nosed Monkey",
"Thomas's Langur",
"Purple-faced Langur",
"Gelada"
}
};

var button = new Button
{
Text = "Change a layout orientation",
AutomationId = "ChangeLayoutButton"
};
button.Clicked += (s, e) =>
{
collectionView.ItemsLayout = new GridItemsLayout(4, ItemsLayoutOrientation.Horizontal);
};


var root = new Grid
{
Margin = new Thickness(20),
RowDefinitions =
{
new RowDefinition(GridLength.Auto),
new RowDefinition(GridLength.Auto),
new RowDefinition(GridLength.Star)
}
};

root.Add(instructions);
root.Add(button, row: 1);
root.Add(collectionView, row: 2);
Content = root;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue38059 : _IssuesUITest
{
public Issue38059(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "CollectionView VerticalGrid has excessive spacing without an ItemTemplate";

[Test, Order(0)]
[ShardedTestCategory(UITestCategories.CollectionView)]
public void Issue38059_UntemplatedVerticalGridLayout()
{
App.WaitForElement("InstructionsLabel");
VerifyScreenshot();
}

[Test, Order(1)]
[ShardedTestCategory(UITestCategories.CollectionView)]
public void Issue38059_UntemplatedHorizontalGridLayout()
{
App.WaitForElement("ChangeLayoutButton");
App.Tap("ChangeLayoutButton");
VerifyScreenshot();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[major] Regression Prevention and Test Coverage — This shared screenshot test runs in every platform test project and in the dedicated Windows CV1 CollectionView lane, but the PR adds the horizontal baseline only under snapshots/android and adds no windows-cv1 baseline for either new method. VerifyScreenshot derives the baseline from this method name plus the environment and explicitly fails when that file is absent, so the horizontal test fails on Windows, iOS/iOS 26, and Mac, while both methods fail in the Windows CV1 lane before they can validate layout behavior. Add the corresponding baselines (or explicitly scope the test to environments for which baselines are supplied).

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading