Skip to content

Conversation

@morning4coffe-dev
Copy link
Contributor

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!

Description of Change

This pull request addresses a bug where images on WinUI did not respect VerticalOptions and HorizontalOptions when using the AspectFit property. The changes include adding a regression test, updating the ImageHandler to handle layout constraints properly.

This change in behavior streamlines it with other targets, where images with those properties are displayed at the size of the source image. It can then be resized to a smaller size after the source size is met with the size of the panel/window.

Current behavior

image

Issues Fixed

Fixes #30403

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 30, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@morning4coffe-dev! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR11 milestone Jul 30, 2025
@jsuarezruiz jsuarezruiz added platform/windows area-image Image loading, sources, caching labels Aug 1, 2025
@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Aug 4, 2025
@morning4coffe-dev morning4coffe-dev marked this pull request as ready for review August 15, 2025 06:49
Copilot AI review requested due to automatic review settings August 15, 2025 06:49
@morning4coffe-dev morning4coffe-dev requested a review from a team as a code owner August 15, 2025 06:49
Copy link
Contributor

Copilot AI left a 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 a bug where images on WinUI did not respect VerticalOptions and HorizontalOptions when using the AspectFit property. The fix ensures that images with AspectFit are displayed at their source image size and can be properly positioned according to layout options.

  • Overrides GetDesiredSize method in ImageHandler.Windows.cs to handle AspectFit layout constraints
  • Adds helper method to retrieve actual image dimensions from BitmapSource
  • Includes regression test to validate the fix

Reviewed Changes

Copilot reviewed 4 out of 15 changed files in this pull request and generated 3 comments.

File Description
src/Core/src/Handlers/Image/ImageHandler.Windows.cs Implements the core fix by overriding GetDesiredSize and adding image size detection
src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt Documents the new public API surface for the GetDesiredSize override
src/Controls/tests/TestCases.HostApp/Issues/Issue30403.cs Creates UI test page demonstrating the image positioning behavior
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30403.cs Implements automated test to verify the fix works correctly

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

The images you've modified are all being modified to closer match the other platforms which is awesome!

Can you rebase this one to net10.0 ? Now that we're getting closer to NET10.0 GA changes like this are better to have their so the cheese isn't moving in net9 at this point.

@github-project-automation github-project-automation bot moved this from In Progress to Changes Requested in MAUI SDK Ongoing Aug 19, 2025
@morning4coffe-dev morning4coffe-dev changed the base branch from main to net10.0 August 20, 2025 14:56
@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Aug 22, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR11, .NET 10.0-rc2 Aug 22, 2025
@github-project-automation github-project-automation bot moved this from Approved to Changes Requested in MAUI SDK Ongoing Aug 22, 2025
@PureWeen
Copy link
Member

PureWeen commented Sep 4, 2025

/rebase

@PureWeen
Copy link
Member

PureWeen commented Sep 4, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

PureWeen
PureWeen previously approved these changes Sep 4, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Sep 4, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

The tests NoScrollbarsTest and ShadowsDontRespectControlShape are failing on Windows with slightly differences in images.

Example:
image

Could you review it?

@github-project-automation github-project-automation bot moved this from Approved to Changes Requested in MAUI SDK Ongoing Sep 16, 2025
@morning4coffe-dev
Copy link
Contributor Author

Thanks, @jsuarezruiz! As discussed during our 1:1, I reuploaded the screenshots

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

With the latest modifications, the fix looks good to me. Just requested to expand the added test to cover edge cases where potentially the changes could have an impact.

{
Title = "Issue 30403";

Content = new Grid
Copy link
Contributor

Choose a reason for hiding this comment

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

Could modify a little bit this test? Could you include a StackLayout with 2-3 images?
Leave the current one, but could also validate:

  • Image with extreme aspect ratio
  • Really small image

Copy link
Contributor

Choose a reason for hiding this comment

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

Created a separate issue to create the tests #31686

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Sep 19, 2025
@rmarinho rmarinho merged commit 4cc543c into dotnet:net10.0 Sep 19, 2025
150 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Sep 19, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-image Image loading, sources, caching community ✨ Community Contribution platform/windows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Image under WinUI does not respect VerticalOptions and HorizontalOptions

4 participants