diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithNullStrokeDashArray.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithNullStrokeDashArray.png new file mode 100644 index 000000000000..80f0193d30e1 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithNullStrokeDashArray.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithStrokeDashArrayValue.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithStrokeDashArrayValue.png new file mode 100644 index 000000000000..9d1114ecd5a0 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyBorderWithStrokeDashArrayValue.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs new file mode 100644 index 000000000000..7bc85c87b19c --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs @@ -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; + } + +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithNullStrokeDashArray.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithNullStrokeDashArray.png new file mode 100644 index 000000000000..0818f7537112 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithNullStrokeDashArray.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithStrokeDashArrayValue.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithStrokeDashArrayValue.png new file mode 100644 index 000000000000..5fa307a896fd Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyBorderWithStrokeDashArrayValue.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29898.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29898.cs new file mode 100644 index 000000000000..85393fbf3d9e --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29898.cs @@ -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(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithNullStrokeDashArray.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithNullStrokeDashArray.png new file mode 100644 index 000000000000..9a59020d0d0d Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithNullStrokeDashArray.png differ diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithStrokeDashArrayValue.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithStrokeDashArrayValue.png new file mode 100644 index 000000000000..70451bc1acbd Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyBorderWithStrokeDashArrayValue.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithNullStrokeDashArray.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithNullStrokeDashArray.png new file mode 100644 index 000000000000..f3e5efda936b Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithNullStrokeDashArray.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithStrokeDashArrayValue.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithStrokeDashArrayValue.png new file mode 100644 index 000000000000..eb464057c89c Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyBorderWithStrokeDashArrayValue.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithNullStrokeDashArray.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithNullStrokeDashArray.png new file mode 100644 index 000000000000..994c64ffb3ad Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithNullStrokeDashArray.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithStrokeDashArrayValue.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithStrokeDashArrayValue.png new file mode 100644 index 000000000000..0950f438f5de Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyBorderWithStrokeDashArrayValue.png differ diff --git a/src/Core/src/Platform/Windows/BorderExtensions.cs b/src/Core/src/Platform/Windows/BorderExtensions.cs index 7823a83cd927..6a8bb22e0c90 100644 --- a/src/Core/src/Platform/Windows/BorderExtensions.cs +++ b/src/Core/src/Platform/Windows/BorderExtensions.cs @@ -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; + } } public static void UpdateBorderDashOffset(this Path borderPath, double borderDashOffset) diff --git a/src/Core/src/Platform/Windows/StrokeExtensions.cs b/src/Core/src/Platform/Windows/StrokeExtensions.cs index 687a06160f33..ef53834bdba2 100644 --- a/src/Core/src/Platform/Windows/StrokeExtensions.cs +++ b/src/Core/src/Platform/Windows/StrokeExtensions.cs @@ -30,9 +30,6 @@ public static void UpdateStrokeDashPattern(this ContentPanel platformView, IBord { var strokeDashPattern = border.StrokeDashPattern; - if (strokeDashPattern == null) - return; - platformView.BorderPath?.UpdateStrokeDashPattern(strokeDashPattern); } diff --git a/src/Core/src/Platform/iOS/MauiCALayer.cs b/src/Core/src/Platform/iOS/MauiCALayer.cs index c8a3818ac07f..091c57812f21 100644 --- a/src/Core/src/Platform/iOS/MauiCALayer.cs +++ b/src/Core/src/Platform/iOS/MauiCALayer.cs @@ -250,6 +250,10 @@ public void SetBorderDash(float[]? borderDashArray, double borderDashOffset) _strokeDash = dashArray; } + else if (borderDashArray is null || borderDashArray.Length == 0) + { + _strokeDash = null; + } SetNeedsDisplay(); }