Skip to content
Open
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
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.
54 changes: 54 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 29898, "[iOS, macOS] StrokeDashArray on Border does not reset when set to null", PlatformAffected.iOS)]
public class Issue29898 : ContentPage
{
public Issue29898()
{
var border = new Border
{
HeightRequest = 200,
WidthRequest = 200,
BackgroundColor = Colors.LightGray,
Stroke = Colors.Blue,
StrokeThickness = 5,
StrokeDashArray = new DoubleCollection { 10, 5 }
};

var button = new Button
{
Text = "Clear StrokeDashArray",
AutomationId = "ClearDashButton",
HorizontalOptions = LayoutOptions.Center
};

var button2 = new Button
{
Text = "Set StrokeDashArray",
AutomationId = "SetDashButton",
HorizontalOptions = LayoutOptions.Center
};

button.Clicked += (s, e) =>
{
border.StrokeDashArray = null;
};

button2.Clicked += (s, e) =>
{
border.StrokeDashArray = new DoubleCollection { 5, 2 };
};

var layout = new VerticalStackLayout
{
Spacing = 25,
Padding = new Thickness(30, 60, 30, 30),
VerticalOptions = LayoutOptions.Center,
Children = { border, button, button2 }
};

Content = layout;
}

}
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29898 : _IssuesUITest
{
public override string Issue => "[iOS, macOS] StrokeDashArray on Border does not reset when set to null";

public Issue29898(TestDevice device)
: base(device)
{ }

[Test, Order(1)]
[Category(UITestCategories.Border)]
public void VerifyBorderWithNullStrokeDashArray()
{
App.WaitForElement("ClearDashButton");
App.Tap("ClearDashButton");
VerifyScreenshot();
}

[Test, Order(2)]
[Category(UITestCategories.Border)]
public void VerifyBorderWithStrokeDashArrayValue()
{
App.WaitForElement("SetDashButton");
App.Tap("SetDashButton");
VerifyScreenshot();
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.

Pending snapshots. Running a build.

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.

Snapshots available in the latest build.
image

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 , I have added the pending snapshot.

}
}
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
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
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.
4 changes: 4 additions & 0 deletions src/Core/src/Platform/Windows/BorderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public static void UpdateStrokeDashPattern(this Path borderPath, float[]? border
borderPath.StrokeDashArray.Add(value);
}
}
else if (borderDashArray is null || borderDashArray.Length == 0)
{
borderPath.StrokeDashArray = null;
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

Assigning StrokeDashArray to null may lead to NullReferenceExceptions when the path renders. It’s safer to call borderPath.StrokeDashArray.Clear() to preserve a valid collection object.

Suggested change
borderPath.StrokeDashArray = null;
if (borderPath.StrokeDashArray == null)
borderPath.StrokeDashArray = new WDoubleCollection();
borderPath.StrokeDashArray.Clear();

Copilot uses AI. Check for mistakes.
}
}

public static void UpdateBorderDashOffset(this Path borderPath, double borderDashOffset)
Expand Down
3 changes: 0 additions & 3 deletions src/Core/src/Platform/Windows/StrokeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public static void UpdateStrokeDashPattern(this ContentPanel platformView, IBord
{
var strokeDashPattern = border.StrokeDashPattern;

if (strokeDashPattern == null)
return;

platformView.BorderPath?.UpdateStrokeDashPattern(strokeDashPattern);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Platform/iOS/MauiCALayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public void SetBorderDash(float[]? borderDashArray, double borderDashOffset)

_strokeDash = dashArray;
}
else if (borderDashArray is null || borderDashArray.Length == 0)
{
_strokeDash = null;
}

SetNeedsDisplay();
}
Expand Down
Loading