diff --git a/src/Controls/src/Core/Handlers/Shell/Windows/ShellFlyoutItemView.cs b/src/Controls/src/Core/Handlers/Shell/Windows/ShellFlyoutItemView.cs index 5718cef5b539..4400e9fa1c0f 100644 --- a/src/Controls/src/Core/Handlers/Shell/Windows/ShellFlyoutItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Windows/ShellFlyoutItemView.cs @@ -128,7 +128,9 @@ void ShellElementPropertyChanged(object sender, PropertyChangedEventArgs e) protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize) { - if (this.ActualWidth > 0 && _content is IView view) + // Replaced ActualWidth with finalSize.Width since ActualWidth updates only after ArrangeOverride completes, + // ensuring accurate layout during the initial arrangement phase. + if (finalSize.Width > 0 && _content is IView view) { view.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); return finalSize; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyTemplateViewMarginOnInitialDisplay.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyTemplateViewMarginOnInitialDisplay.png new file mode 100644 index 000000000000..27c540446f02 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyTemplateViewMarginOnInitialDisplay.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18423.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18423.cs new file mode 100644 index 000000000000..04b0fcd7b185 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18423.cs @@ -0,0 +1,40 @@ +namespace Maui.Controls.Sample.Issues +{ + + [Issue(IssueTracker.Github, 18423, "[Windows] Shell flyout template items do not have a margin applied on first show", PlatformAffected.UWP)] + public partial class Issue18423Shell : Shell + { + public Issue18423Shell() + { + FlyoutBehavior = FlyoutBehavior.Flyout; + + ItemTemplate = new DataTemplate(() => + { + return new Label + { + AutomationId = "LabelWithMargin", + Margin = new Thickness(20), + Text = "Title" + }; + }); + + ShellContent shellContent = new ShellContent + { + Title = "Home", + ContentTemplate = new DataTemplate(typeof(Issue18423Page)), + Route = "MainPage" + }; + + Items.Add(shellContent); + } + } + + public partial class Issue18423Page : ContentPage + { + public Issue18423Page() + { + BackgroundColor = Colors.HotPink; + this.Content = new Label() { AutomationId = "MainPageLabel", Text = "Content" }; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTemplateViewMarginOnInitialDisplay.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTemplateViewMarginOnInitialDisplay.png new file mode 100644 index 000000000000..9543ba18bbca Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyTemplateViewMarginOnInitialDisplay.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18423.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18423.cs new file mode 100644 index 000000000000..c1d01d3a3953 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18423.cs @@ -0,0 +1,24 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue18423 : _IssuesUITest + { + public Issue18423(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "[Windows] Shell flyout template items do not have a margin applied on first show"; + + [Test] + [Category(UITestCategories.Shell)] + public void VerifyTemplateViewMarginOnInitialDisplay() + { + App.WaitForElement("MainPageLabel"); + App.TapShellFlyoutIcon(); + VerifyScreenshot(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTemplateViewMarginOnInitialDisplay.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTemplateViewMarginOnInitialDisplay.png new file mode 100644 index 000000000000..8a35c1caf216 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyTemplateViewMarginOnInitialDisplay.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyTemplateViewMarginOnInitialDisplay.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyTemplateViewMarginOnInitialDisplay.png new file mode 100644 index 000000000000..c3665cffd10e Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyTemplateViewMarginOnInitialDisplay.png differ