diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ClipShouldApplyProperlyToTheContentOfBorder.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ClipShouldApplyProperlyToTheContentOfBorder.png new file mode 100644 index 000000000000..5d68ae5a0a54 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ClipShouldApplyProperlyToTheContentOfBorder.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue30404.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue30404.cs new file mode 100644 index 000000000000..57f476ddaa0a --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue30404.cs @@ -0,0 +1,52 @@ +using Microsoft.Maui.Controls.Shapes; +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 30404, "[Windows] ContentView clip is not updated when wrapping inside the Border", PlatformAffected.UWP)] +public class Issue30404 : ContentPage +{ + public Issue30404() + { + var border = new Border + { + HeightRequest = 200, + BackgroundColor = Colors.Green, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + var customView = new Issue30404CustomContentView + { + HeightRequest = 100, + WidthRequest = 100, + }; + + border.Content = customView; + Content = border; + } +} + +public class Issue30404CustomContentView : ContentView +{ + public Issue30404CustomContentView() + { + BackgroundColor = Colors.Red; + Content = new Label + { + Text = "Clipped Content", + TextColor = Colors.Blue, + AutomationId = "BorderContentLabel", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + SizeChanged += OnSizeChanged; + } + + private void OnSizeChanged(object sender, EventArgs e) + { + if (Width > 0 && Height > 0) + { + Clip = new RoundRectangleGeometry(25, new Rect(0, 0, Width, Height)); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30404.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30404.cs new file mode 100644 index 000000000000..a9186ac8085a --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30404.cs @@ -0,0 +1,22 @@ +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST // Content of the border disappears when apply clip to it see https://github.com/dotnet/maui/issues/14164 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue30404 : _IssuesUITest +{ + public Issue30404(TestDevice device) : base(device) { } + + public override string Issue => "[Windows] ContentView clip is not updated when wrapping inside the Border"; + + [Test] + [Category(UITestCategories.Border)] + public void ClipShouldApplyProperlyToTheContentOfBorder() + { + App.WaitForElement("BorderContentLabel"); + VerifyScreenshot(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ClipShouldApplyProperlyToTheContentOfBorder.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ClipShouldApplyProperlyToTheContentOfBorder.png new file mode 100644 index 000000000000..f53592f22f44 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ClipShouldApplyProperlyToTheContentOfBorder.png differ diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 61c4e6677e2a..52e1d0d699f9 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -182,6 +182,13 @@ void UpdateClip(IShape? borderShape, double width, double height) } var visual = ElementCompositionPreview.GetElementVisual(Content); + + // Prevent clip collision: When ContentView is inside Border, let WrapperView handle + // clipping to avoid Border overwriting ContentView's clip geometry during SizeChanged. + if (visual.Clip != null && Content.Parent is WrapperView) + { + return; + } var compositor = visual.Compositor; PathF? clipPath;