-
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
Conversation
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -162,7 +163,7 @@ void UpdateBorder(IShape? strokeShape) | |||
UpdateClip(strokeShape, width, height); | |||
} | |||
|
|||
void UpdateClip(IShape? borderShape, double width, double height) | |||
async void UpdateClip(IShape? borderShape, double width, double height) |
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.
Could avoid async void? Because error propagation and also the call stack may not accurately represent the execution flow at the time the exception was thrown, complicating the process of identifying and fixing bugs.
Return a Task and rename the method to UpdateClipAsync
.
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.
@jsuarezruiz, I have renamed the method to UpdateClipAsync
and changed its return type to Task. Could you please check once and let me know if you have any concerns?
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
} | ||
|
||
void UpdateClip(IShape? borderShape, double width, double height) | ||
async Task UpdateClipAsync(IShape? borderShape, double width, double height) |
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 a Visual
-- 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
to LayoutUpdated
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?
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.
WinAppSDK folks also suggested to try switching
SizeChanged
toLayoutUpdated
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 use Composition.Visual.Clip
:
protected override WSize ArrangeOverride(WSize finalSize)
{
var actual = base.ArrangeOverride(finalSize);
var visual = ElementCompositionPreview.GetElementVisual(this);
visual.Clip = ClipsToBounds ? visual.Compositor.CreateInsetClip() : null;
return actual;
}
Then, add a check in ContentPanel.cs to ensure the clip isn't overridden:
void UpdateClip(IShape? borderShape, double width, double height)
{
if (Content is null)
{
return;
}
if (height <= 0 && width <= 0)
{
return;
}
// Ensure clip isn't overridden on LayoutPanel
if (Content is LayoutPanel panel && panel.ClipsToBounds)
{
return;
}
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
:protected override WSize ArrangeOverride(WSize finalSize) { var actual = base.ArrangeOverride(finalSize); var visual = ElementCompositionPreview.GetElementVisual(this); visual.Clip = ClipsToBounds ? visual.Compositor.CreateInsetClip() : null; return actual; }Then, add a check in ContentPanel.cs to ensure the clip isn't overridden:
void UpdateClip(IShape? borderShape, double width, double height) { if (Content is null) { return; } if (height <= 0 && width <= 0) { return; } // Ensure clip isn't overridden on LayoutPanel if (Content is LayoutPanel panel && panel.ClipsToBounds) { return; }
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?
Azure Pipelines successfully started running 3 pipeline(s). |
Is this only fixed in .net 9.0? Most of us are on .NET 8 which is LTS (L means Long btw). |
Root Cause
Description of Change
Issues Fixed
Fixes #18937
Screenshot
ClippedToBoundsIssue.mp4
ClippedToBoundsFixed.mp4