diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
index 0ae16e3e8be6..189b4ea19fdd 100644
--- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
+++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
@@ -109,24 +109,8 @@ void UpdateEmptyViewSize(double width, double height)
if (adapter is EmptyViewAdapter emptyViewAdapter)
{
- var emptyView = emptyViewAdapter.EmptyView ?? emptyViewAdapter.EmptyViewTemplate;
- Size size = Size.Zero;
-
- IView view = emptyView as IView ?? (emptyView as DataTemplate)?.CreateContent() as IView;
-
- if (view is not null)
- {
- if (view.Handler is null)
- {
- TemplateHelpers.GetHandler(view as View, this.MauiContext);
- }
-
- size = view.Measure(double.PositiveInfinity, double.PositiveInfinity);
- }
-
- var measuredHeight = !double.IsInfinity(size.Height) ? Context.ToPixels(size.Height) : height;
emptyViewAdapter.RecyclerViewWidth = width;
- emptyViewAdapter.RecyclerViewHeight = measuredHeight > 0 ? measuredHeight : height;
+ emptyViewAdapter.RecyclerViewHeight = height;
}
}
}
diff --git a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
index 0206954ee746..02ea6ccb1486 100644
--- a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
+++ b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
@@ -538,13 +538,8 @@ protected virtual void RegisterViewTypes()
protected virtual CGRect DetermineEmptyViewFrame()
{
- nfloat emptyViewHeight = CollectionView.Frame.Height;
-
- if (_emptyViewFormsElement is IView emptyView)
- {
- emptyViewHeight = (nfloat)emptyView.Measure(CollectionView.Frame.Width, double.PositiveInfinity).Height;
- }
- return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y, CollectionView.Frame.Width, emptyViewHeight);
+ return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y,
+ CollectionView.Frame.Width, CollectionView.Frame.Height);
}
protected void RemeasureLayout(VisualElement formsElement)
diff --git a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
index 8cebe04f6b27..b43468962f47 100644
--- a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
+++ b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
@@ -70,20 +70,15 @@ protected override CGRect DetermineEmptyViewFrame()
nfloat headerHeight = 0;
var headerView = CollectionView.ViewWithTag(HeaderTag);
- if (headerView is not null)
+ if (headerView != null)
headerHeight = headerView.Frame.Height;
nfloat footerHeight = 0;
var footerView = CollectionView.ViewWithTag(FooterTag);
- if (footerView is not null)
+ if (footerView != null)
footerHeight = footerView.Frame.Height;
- var emptyView = CollectionView.ViewWithTag(EmptyTag);
-
- if (emptyView is not null)
- return base.DetermineEmptyViewFrame();
-
return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y, CollectionView.Frame.Width,
Math.Abs(CollectionView.Frame.Height - (headerHeight + footerHeight)));
}
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png
new file mode 100644
index 000000000000..80c9bffaae6c
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png differ
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png
deleted file mode 100644
index 6f6b3134ee77..000000000000
Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png and /dev/null differ
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml
deleted file mode 100644
index 64f2ba7cf960..000000000000
--- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml.cs
deleted file mode 100644
index 2839cb7126eb..000000000000
--- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24966.xaml.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
-using System.Windows.Input;
-using System.Collections.Specialized;
-
-namespace Maui.Controls.Sample.Issues
-{
- [XamlCompilation(XamlCompilationOptions.Compile)]
- [Issue(IssueTracker.Github, 24966, "CollectionView, the footer moves to the bottom of the page when the empty view or empty view template is enabled")]
- public partial class Issue24966
- {
- public Issue24966()
- {
- InitializeComponent();
- BindingContext = new Issue24966ViewModel();
- }
- }
- internal class Issue24966ViewModel
- {
- // Define a static list of cities to add to the collection
- private List _staticCities = new()
- {
- "Paris",
- "New York",
- "Tokyo",
- "Berlin",
- "Madrid",
- "London"
- };
-
- private int _currentIndex = 0;
-
- public ObservableCollection ItemList { get; set; }
-
- public ICommand AddCommand => new Command(Add);
- public ICommand RemoveCommand => new Command(Remove);
-
- public Issue24966ViewModel()
- {
- // Initialize the ItemList
- ItemList = new ObservableCollection();
- }
-
- private void Add()
- {
- // Add the next city from the static list
- if (_currentIndex < _staticCities.Count)
- {
- ItemList.Add(_staticCities[_currentIndex]);
- _currentIndex++;
- }
- else
- {
- // Optionally reset the index or handle the end of the list as needed
- _currentIndex = 0; // Resetting to allow cycling through the list again
- }
- }
-
- private void Remove()
- {
- // Remove the last item in the list if any exist
- if (ItemList.Count > 0)
- {
- ItemList.RemoveAt(ItemList.Count - 1);
- // Decrement the index to ensure the correct city is added next time
- _currentIndex = Math.Max(0, _currentIndex - 1);
- }
- }
- }
-}
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml
new file mode 100644
index 000000000000..6a9d44e400e5
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml.cs
new file mode 100644
index 000000000000..87a67b172613
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27229.xaml.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Windows.Input;
+using System.Collections.Specialized;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ [Issue(IssueTracker.Github, 27229, "CollectionView, EmptyView Fills Available Space By Default")]
+ public partial class Issue27229
+ {
+ public Issue27229()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png
new file mode 100644
index 000000000000..05dc1088b14f
Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png differ
diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png
deleted file mode 100644
index 917ee3b824f1..000000000000
Binary files a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png and /dev/null differ
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24966.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24966.cs
deleted file mode 100644
index 6780ec1d9fe4..000000000000
--- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24966.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-#if TEST_FAILS_ON_WINDOWS // more information: https://github.com/dotnet/maui/issues/24968
-using NUnit.Framework;
-using UITest.Appium;
-using UITest.Core;
-
-namespace Microsoft.Maui.TestCases.Tests.Issues
-{
- internal class Issue24966 : _IssuesUITest
- {
- public Issue24966(TestDevice device) : base(device) { }
-
- public override string Issue => "CollectionView, the footer moves to the bottom of the page when the empty view or empty view template is enabled";
-
- [Test]
- [Category(UITestCategories.CollectionView)]
- public void CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate()
- {
- App.WaitForElement("AddButton");
- App.Tap("AddButton");
- App.Tap("AddButton");
- App.Tap("RemoveButton");
- App.Tap("RemoveButton");
- // Here we check for dynamic Emptyview and Footer proper proper alignment in view it should not be at the bottom of screen.
- VerifyScreenshot();
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27229.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27229.cs
new file mode 100644
index 000000000000..9eeada177912
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27229.cs
@@ -0,0 +1,23 @@
+#if TEST_FAILS_ON_WINDOWS
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ internal class Issue27229 : _IssuesUITest
+ {
+ public Issue27229(TestDevice device) : base(device) { }
+
+ public override string Issue => "CollectionView, EmptyView Fills Available Space By Default";
+
+ [Test]
+ [Category(UITestCategories.CollectionView)]
+ public void CollectionViewEmptyViewFillsAvailableSpaceByDefault()
+ {
+ App.WaitForElement("ReadyToTest");
+ VerifyScreenshot();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png
new file mode 100644
index 000000000000..19fd9ebf5c68
Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewEmptyViewFillsAvailableSpaceByDefault.png differ
diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png
deleted file mode 100644
index 6d1309a31c03..000000000000
Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate.png and /dev/null differ