Skip to content

Commit

Permalink
[Windows] Fix for setting IsClippedToBounds="True" inside a Border co…
Browse files Browse the repository at this point in the history
…ntrol will crash on Windows (#25506)

* Fixed 18937

* Modified test sample.

* Updated the fix.

* Simplified the test case.

* Removed platform condition.

* Changed return type.

* ContentPanel changes.

* Revert unwanted changes
  • Loading branch information
Tamilarasan-Paranthaman authored Dec 5, 2024
1 parent 397b3ff commit a1cd4bc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
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

0 comments on commit a1cd4bc

Please sign in to comment.