-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
+55
−2
Merged
[Windows] Fix for setting IsClippedToBounds="True" inside a Border control will crash on Windows #25506
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
388c3c8
Fixed 18937
Tamilarasan-Paranthaman c5b6682
Modified test sample.
Tamilarasan-Paranthaman a81a447
Updated the fix.
Tamilarasan-Paranthaman 65b7ea7
Simplified the test case.
Tamilarasan-Paranthaman 13ce9bc
Removed platform condition.
Tamilarasan-Paranthaman 943c085
Changed return type.
Tamilarasan-Paranthaman 82eaee9
ContentPanel changes.
Tamilarasan-Paranthaman 07b2ef6
Revert unwanted changes
Tamilarasan-Paranthaman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/Controls/tests/TestCases.HostApp/Issues/Issue18937.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/Controls/tests/TestCases.HostApp/Issues/Issue18937.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18937.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right way to approach this problem. Let me try and ping some WinAppSDK folks and see if they have any suggestions.
In the meantime: the
Loaded
event should be fired after layout is complete on aVisual
-- maybe you can check if that has fired first before assigning the clip?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WinAppSDK folks also suggested to try switching
SizeChanged
toLayoutUpdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With our PR fix, the Loaded event is fired before assigning the clip, ensuring that the layout is completed on the visual before applying the clip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ensured the functionality by calling the UpdateClip method on the LayoutUpdated event, as LayoutUpdated triggers frequently whenever the layout is updated. However, we only need to update the clip during the initial load and when the size changes. To address this, we added flags to limit updates to these specific scenarios. Despite this, after switching from the SizeChanged event to the LayoutUpdated event, the issue persists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've narrowed down the root cause of the issue, and reported it here: https://github.com/microsoft/WindowsAppSDK/issues/4914
We can remove all use of async. To fix this:
In LayoutPanel.cs change
ArrangeOverride
to useComposition.Visual.Clip
:Then, add a check in ContentPanel.cs to ensure the clip isn't overridden:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the suggested fix, I tested it using other shapes in the border, such as Ellipse and RoundRectangle. I observed that clipping was not properly applied due to the clipping logic already being handled in the LayoutPanel and returned in the UpdateClip method of the ContentPanel class.
As a result, the additional clipping code in the UpdateClip based on the border shape was not executed, leading to improper clipping in the UI. To address this, I fixed the issue in the LayoutPanel by skipping the clipping when the parent is a Border. In such cases, clipping will now be handled by the ContentPanel.
Could you please review the changes and let me know if you have any concerns?