diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs index f1d75f9cba54..cf3a7196fae8 100644 --- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs +++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs @@ -335,6 +335,12 @@ protected virtual void UpdateEmptyView() break; } + if (_formsEmptyView is not null && _emptyView is not null) + { + var margin = _formsEmptyView.Margin; + _emptyView.Margin = WinUIHelpers.CreateThickness(margin.Left, margin.Top, margin.Right, margin.Bottom); + } + (ListViewBase as IEmptyView)?.SetEmptyView(_emptyView, _formsEmptyView); UpdateEmptyViewVisibility(); diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CheckEmptyViewMargin.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CheckEmptyViewMargin.png new file mode 100644 index 000000000000..16e009d83f91 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CheckEmptyViewMargin.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue8494.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue8494.cs new file mode 100644 index 000000000000..8cb2cc230032 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue8494.cs @@ -0,0 +1,66 @@ +using System.Collections.ObjectModel; + +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 8494, "Margin doesn't work inside CollectionView EmptyView", PlatformAffected.UWP)] + +public class Issue8494 : ContentPage +{ + Issue8494EmptyViewModel ViewModel; + + public Issue8494() + { + ViewModel = new Issue8494EmptyViewModel(); + BindingContext = ViewModel; + var label = new Label + { + Text = "EmptyView should be laid out with respect to the Specified margin", + AutomationId = "EmptyViewDescriptionLabel", + }; + + var emptyViewLayout = new StackLayout + { + Margin = new Thickness(40), + Background = Colors.Yellow, + Children = + { + new Label + { + Text = "EmptyView with Margin.", + BackgroundColor = Colors.Blue, + HorizontalTextAlignment = TextAlignment.Center, + }, + } + }; + + var collectionView = new CollectionView + { + ItemsSource = ViewModel.ItemList, + BackgroundColor = Colors.Green, + EmptyView = emptyViewLayout, + }; + + var grid = new Grid + { + RowDefinitions = + { + new RowDefinition { Height = GridLength.Auto }, + new RowDefinition { Height = GridLength.Star }, + } + }; + + grid.Add(label, 0, 0); + grid.Add(collectionView, 0, 1); + Content = grid; + } +} + +public class Issue8494EmptyViewModel +{ + public ObservableCollection ItemList { get; set; } + + public Issue8494EmptyViewModel() + { + ItemList = new ObservableCollection(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CheckEmptyViewMargin.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CheckEmptyViewMargin.png new file mode 100644 index 000000000000..36c2645557b8 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CheckEmptyViewMargin.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8494.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8494.cs new file mode 100644 index 000000000000..7e1dc6eaee84 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue8494.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue8494 : _IssuesUITest +{ + public Issue8494(TestDevice testDevice) : base(testDevice) + { + } + public override string Issue => "Margin doesn't work inside CollectionView EmptyView"; + + [Test] + [Category(UITestCategories.CollectionView)] + public void CheckEmptyViewMargin() + { + App.WaitForElement("EmptyViewDescriptionLabel"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/CheckEmptyViewMargin.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/CheckEmptyViewMargin.png new file mode 100644 index 000000000000..051b12008214 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/CheckEmptyViewMargin.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/CheckEmptyViewMargin.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/CheckEmptyViewMargin.png new file mode 100644 index 000000000000..3abee6d0f03f Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/CheckEmptyViewMargin.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CheckEmptyViewMargin.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CheckEmptyViewMargin.png new file mode 100644 index 000000000000..96956f310ab0 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/CheckEmptyViewMargin.png differ