Skip to content
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
10 changes: 8 additions & 2 deletions src/Controls/src/Core/Shapes/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
var result = base.MeasureOverride(widthConstraint, heightConstraint);
RectF pathBounds;

if (result.Width != 0 && result.Height != 0)
if (result.Width != 0 && result.Height != 0 && result.Width > Margin.HorizontalThickness && result.Height > Margin.VerticalThickness)
{
return result;
}
Expand All @@ -391,7 +391,7 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
}
else
{
pathBounds = this.GetPath().GetBoundsByFlattening(1);
pathBounds = this.GetPath().GetBoundsByFlattening(1);
}

SizeF boundsByFlattening = pathBounds.Size;
Expand Down Expand Up @@ -450,6 +450,12 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon

result.Height += StrokeThickness;
result.Width += StrokeThickness;
if (this is Line or Path or Polyline)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is required for Line, PolyLine and Path and not for example for Polyline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz, In non-closed shapes such as Line, Polyline, and Path, the margin is not considered when the shape is inside a StackLayout and no explicit size is defined. The base size value is returned before measuring the path size because the measured result includes the margin, causing the shape to be invisible.
When the height or width is not explicitly set for these shapes, the shape size is reset using boundsByFlattening and does not account for the margin. Hence, the margin is now added at the end of non-closed shapes

{
result.Height += Margin.VerticalThickness;
result.Width += Margin.HorizontalThickness;
}

return result;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue13801.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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.Issue13801">

<StackLayout VerticalOptions="Start">
<Label AutomationId="PathLabel"
Text="Path with Margin"/>
<Path Stroke="Red"
StrokeThickness="5"
Data="M 0 0 L 100 0 L 100 100 L 0 100 Z"
Margin="20"/>
<Path Stroke="Blue"
StrokeThickness="5"
Data="M 0 0 L 100 0 L 100 100 L 0 100 Z"
Margin="-10"/>
<Label Text="Polyline with Margin"
Margin="0,15,0,0"/>
<Polyline Stroke="Purple"
StrokeThickness="5"
Points="10,10 40,25 70,10 70,40 40,55 10,40 10,10"
Margin="20"
HorizontalOptions="Start"/>
<Polyline Stroke="Pink"
StrokeThickness="5"
Points="10,10 40,25 70,10 70,40 40,55 10,40 10,10"
Margin="-10"
HorizontalOptions="Start"/>
<Label Text="Line with Margin"
Margin="0,15,0,0"/>
<Line Stroke="Green"
StrokeThickness="5"
X1="0"
Y1="0"
X2="100"
Y2="50"
Margin="20"/>
<Line Stroke="Orange"
StrokeThickness="5"
X1="0"
Y1="0"
X2="100"
Y2="50"
Margin="-10"/>
</StackLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue13801.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 13801, "Path does not render if it has Margin", PlatformAffected.All)]
public partial class Issue13801 : ContentPage
{
public Issue13801()
{
InitializeComponent();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Issue13801 : _IssuesUITest
{
public override string Issue => "Path does not render if it has Margin";

public Issue13801(TestDevice testDevice) : base(testDevice) { }

[Test]
[Category(UITestCategories.Shape)]
public void Issue13801VerifyPathMargin()
{
App.WaitForElement("PathLabel");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading