Fix StrokeDashArray on Border does not reset when set to null #29910
Fix StrokeDashArray on Border does not reset when set to null #29910devanathan-vaithiyanathan wants to merge 10 commits intodotnet:mainfrom
Conversation
|
Hey there @@devanathan-vaithiyanathan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where setting Border.StrokeDashArray to null (or an empty array) did not clear the previously applied dash pattern on iOS and macOS Catalyst. It adds matching logic on Windows and Android platforms and includes a new UI sample and automated tests to verify the behavior.
- Handle null/empty dash arrays in the iOS
MauiCALayerimplementation - Mirror the “clear dash” logic in Windows and Android renderers
- Add a sample page and UI tests to confirm both clearing and setting dash patterns
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/src/Platform/iOS/MauiCALayer.cs | Reset _strokeDash to null when dash array is null or empty |
| src/Core/src/Platform/Windows/StrokeExtensions.cs | Remove early return so null dash arrays propagate to UpdateStrokeDashPattern |
| src/Core/src/Platform/Windows/BorderExtensions.cs | Clear StrokeDashArray on null/empty dash arrays |
| src/Core/src/Graphics/MauiDrawable.Android.cs | Reset _borderPathEffect and clear paint path effect on null/empty |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29898.cs | Add UI tests for “Clear” and “Set” dash buttons |
| src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs | Add sample page with Clear/Set buttons for manual testing |
Comments suppressed due to low confidence (2)
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29898.cs:21
- Consider adding a third test that sets
StrokeDashArrayto an empty collection (new DoubleCollection()) to verify that the empty-array branch also correctly clears the dash pattern.
VerifyScreenshot();
src/Controls/tests/TestCases.HostApp/Issues/Issue29898.cs:19
- [nitpick] The local variables
buttonandbutton2are ambiguous; consider renaming them toclearDashButtonandsetDashButtonfor better readability.
var button = new Button
| } | ||
| else if (borderDashArray is null || borderDashArray.Length == 0) | ||
| { | ||
| borderPath.StrokeDashArray = null; |
There was a problem hiding this comment.
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.
| borderPath.StrokeDashArray = null; | |
| if (borderPath.StrokeDashArray == null) | |
| borderPath.StrokeDashArray = new WDoubleCollection(); | |
| borderPath.StrokeDashArray.Clear(); |
| _borderPathEffect = null; | ||
| if (_borderPaint != null) | ||
| { | ||
| _borderPaint.SetPathEffect(null); |
There was a problem hiding this comment.
After clearing the path effect on the paint, call InvalidateSelf() (or the equivalent) on the drawable to ensure the UI is redrawn immediately.
| _borderPaint.SetPathEffect(null); | |
| _borderPaint.SetPathEffect(null); | |
| InvalidateSelf(); |
There was a problem hiding this comment.
InvalidateSelf(); is invoked in line 311
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| { | ||
| App.WaitForElement("SetDashButton"); | ||
| App.Tap("SetDashButton"); | ||
| VerifyScreenshot(); |
There was a problem hiding this comment.
Pending snapshots. Running a build.
There was a problem hiding this comment.
@jsuarezruiz , I have added the pending snapshot.
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
c47278b to
0b43994
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 29910Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 29910" |

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details:
Setting Border.StrokeDashArray to null does not remove the previously applied dash pattern, causing the dashed border to remain visible.
Description of Change
Handled the case where StrokeDashArray is set to null by resetting the native dash pattern to ensure the stroke renders as a solid line.
Issues Fixed
Fixes #29898
Fixes #22326
Tested the behavior in the following platforms.
iOS-BeforeFix.mov
iOS-AfterFix.mov