Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix for setting IsClippedToBounds="True" inside a Border control will crash on Windows #25506

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18937.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue18937">

<Border>
<StackLayout BackgroundColor="red"
IsClippedToBounds="True">
<Label AutomationId="Label"
Text="Label Inside the Border"
VerticalOptions="Center"
HorizontalOptions="Center"/>
</StackLayout>
</Border>

</ContentPage>
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue18937.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Maui.Controls.Sample.Issues
{

[Issue(IssueTracker.Github, 18937, "[Windows] Setting IsClippedToBound is true inside a Border control will crash on Windows", PlatformAffected.UWP)]
public partial class Issue18937 : ContentPage
{
public Issue18937()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue18937 : _IssuesUITest
{
public Issue18937(TestDevice device) : base(device) { }

public override string Issue => "[Windows] Setting IsClippedToBound is true inside a Border control will crash on Windows";

[Test]
[Category(UITestCategories.Border)]
public void ExceptionShouldNotOccurWhenIsClippedToBoundsIsTrue()
{
var testLabel = App.WaitForElement("Label");
Assert.That(testLabel.GetText(), Is.EqualTo("Label Inside the Border"));
}
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Windows/ContentPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ContentPanel : MauiPanel
FrameworkElement? _content;

internal Path? BorderPath => _borderPath;

internal IBorderStroke? BorderStroke => _borderStroke;
internal FrameworkElement? Content
{
get => _content;
Expand Down
5 changes: 4 additions & 1 deletion src/Core/src/Platform/Windows/LayoutPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ protected override WSize ArrangeOverride(WSize finalSize)
{
var actual = base.ArrangeOverride(finalSize);

Clip = ClipsToBounds ? new RectangleGeometry { Rect = new WRect(0, 0, finalSize.Width, finalSize.Height) } : null;
if (!(Parent is ContentPanel contentPanel && contentPanel.BorderStroke?.Shape is not null))
{
Clip = ClipsToBounds ? new RectangleGeometry { Rect = new WRect(0, 0, finalSize.Width, finalSize.Height) } : null;
}

return actual;
}
Expand Down
Loading