Fixed Maui.Graphics GetStringSize Inverts Width and Height#29574
Merged
PureWeen merged 6 commits intodotnet:inflight/currentfrom May 21, 2025
Merged
Fixed Maui.Graphics GetStringSize Inverts Width and Height#29574PureWeen merged 6 commits intodotnet:inflight/currentfrom
PureWeen merged 6 commits intodotnet:inflight/currentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the incorrect sizing of text in Maui.Graphics by explicitly setting CanvasWordWrapping to NoWrap before measuring the text.
- The Windows platform implementation now reinstates NoWrap for GetStringSize.
- New test cases in both TestCases.Shared.Tests and TestCases.HostApp verify that text is rendered as a single line.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Graphics/src/Graphics/Platforms/Windows/PlatformStringSizeService.cs | Fixes GetStringSize by setting WordWrapping to NoWrap |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29562.cs | Adds automated test for verifying single-line text rendering |
| src/Controls/tests/TestCases.HostApp/Issues/Issue29562.cs | Provides UI test integration to validate the fix |
Contributor
|
/azp run MAUI-UITests-public |
jsuarezruiz
suggested changes
May 20, 2025
| public void GraphicsViewShouldNotWrapText() | ||
| { | ||
| App.WaitForElement("Label"); | ||
| VerifyScreenshot(); |
Contributor
There was a problem hiding this comment.
Pending snapshots. Running a build.
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
approved these changes
May 21, 2025
PureWeen
pushed a commit
that referenced
this pull request
May 21, 2025
* Fixed incorrect width and height * Updated test sample * Updated method name * Update shared test sample * Given width and height request for graphicsview in sample * Added snapshots
github-actions bot
pushed a commit
that referenced
this pull request
May 22, 2025
* Fixed incorrect width and height * Updated test sample * Updated method name * Update shared test sample * Given width and height request for graphicsview in sample * Added snapshots
github-actions bot
pushed a commit
that referenced
this pull request
May 30, 2025
* Fixed incorrect width and height * Updated test sample * Updated method name * Update shared test sample * Given width and height request for graphicsview in sample * Added snapshots
github-actions bot
pushed a commit
that referenced
this pull request
May 30, 2025
* Fixed incorrect width and height * Updated test sample * Updated method name * Update shared test sample * Given width and height request for graphicsview in sample * Added snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
The values returned by canvas.GetStringSize has incorrect width and height measurements.
Root Cause
In recent changes, removed CanvasWordWrapping = NoWrap caused incorrect width and height calculations due to unintended word wrapping.
Description of Change
The fix explicitly reinstates the CanvasWordWrapping setting to NoWrap before measuring the text. This ensures that GetStringSize returns correct dimensions for single-line content, resulting in accurate rectangle sizing and proper alignment.
Validated the behaviour in the following platforms
Break PR: 29048
Issues Fixed:
Fixes #29562
Screenshots