-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix StrokeDashArray on Border does not reset when set to null #29910
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
base: main
Are you sure you want to change the base?
Fix StrokeDashArray on Border does not reset when set to null #29910
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
Copilot
AI
Jun 11, 2025
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.
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); |
Copilot
AI
Jun 11, 2025
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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.
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 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