diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Layouts/UniformItemsLayoutPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Layouts/UniformItemsLayoutPage.xaml
index 63dd040f28..b235750b09 100644
--- a/samples/CommunityToolkit.Maui.Sample/Pages/Layouts/UniformItemsLayoutPage.xaml
+++ b/samples/CommunityToolkit.Maui.Sample/Pages/Layouts/UniformItemsLayoutPage.xaml
@@ -114,6 +114,15 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/UniformItemsLayoutViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/UniformItemsLayoutViewModel.cs
index 1c7c1cbd51..ee3d76c4a1 100644
--- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/UniformItemsLayoutViewModel.cs
+++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Layouts/UniformItemsLayoutViewModel.cs
@@ -1,6 +1,16 @@
-namespace CommunityToolkit.Maui.Sample.ViewModels.Layouts;
+using System.Collections.ObjectModel;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
-public class UniformItemsLayoutViewModel : BaseViewModel
+namespace CommunityToolkit.Maui.Sample.ViewModels.Layouts;
+
+public partial class UniformItemsLayoutViewModel : BaseViewModel
{
+ [RelayCommand]
+ void AddItem()
+ {
+ Items.Add(Path.GetRandomFileName());
+ }
+ public ObservableCollection Items { get; } = new();
}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.Core/Layouts/UniformItemsLayoutManager.shared.cs b/src/CommunityToolkit.Maui.Core/Layouts/UniformItemsLayoutManager.shared.cs
index d3925a50c5..b492ede9f2 100644
--- a/src/CommunityToolkit.Maui.Core/Layouts/UniformItemsLayoutManager.shared.cs
+++ b/src/CommunityToolkit.Maui.Core/Layouts/UniformItemsLayoutManager.shared.cs
@@ -65,7 +65,7 @@ public override Size Measure(double widthConstraint, double heightConstraint)
if (childWidth == 0)
{
- var sizeRequest = visibleChildren[0].Measure(double.PositiveInfinity, double.PositiveInfinity);
+ var sizeRequest = visibleChildren.Length == 0 ? Size.Zero : visibleChildren[0].Measure(double.PositiveInfinity, double.PositiveInfinity);
childWidth = sizeRequest.Width;
childHeight = sizeRequest.Height;
diff --git a/src/CommunityToolkit.Maui.UnitTests/Layouts/UniformItemsLayoutTests.cs b/src/CommunityToolkit.Maui.UnitTests/Layouts/UniformItemsLayoutTests.cs
index 87eabb0d0f..557c369f6e 100644
--- a/src/CommunityToolkit.Maui.UnitTests/Layouts/UniformItemsLayoutTests.cs
+++ b/src/CommunityToolkit.Maui.UnitTests/Layouts/UniformItemsLayoutTests.cs
@@ -59,6 +59,17 @@ public void MeasureUniformItemsLayout_NoWrap()
Assert.Equal(expectedSize, actualSize);
}
+ [Fact]
+ public void MeasureUniformItemsLayout_NoItems_ZeroSize()
+ {
+ var expectedSize = Size.Zero;
+ var emptyUniformItemsLayout = new UniformItemsLayout();
+
+ var actualSize = emptyUniformItemsLayout.CrossPlatformMeasure(double.PositiveInfinity, double.PositiveInfinity);
+
+ Assert.Equal(expectedSize, actualSize);
+ }
+
[Fact]
public void MeasureUniformItemsLayout_WrapOnNextRow()
{