Skip to content

Fix ImageButton not rendering correctly based on its bounds#28309

Merged
PureWeen merged 11 commits into
dotnet:inflight/currentfrom
Shalini-Ashokan:fix-25558
Feb 17, 2026
Merged

Fix ImageButton not rendering correctly based on its bounds#28309
PureWeen merged 11 commits into
dotnet:inflight/currentfrom
Shalini-Ashokan:fix-25558

Conversation

@Shalini-Ashokan

@Shalini-Ashokan Shalini-Ashokan commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

Issue Details

The ImageButton image rendered on Android was not adjusting its bounds correctly, leading to improper scaling.

Root Cause

The image button was not rendering based on its bounds value.

Description of Change

In ImageButton Android Handler, set true for SetAdjustViewBounds(), when you enable view bounds adjustment, the ImageView will automatically resize to maintain the image's aspect ratio.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #25558
Fixes #14346

Output ScreenShot

Before After
Screenshot 2025-03-11 at 3 23 41 PM Screenshot 2025-03-11 at 3 27 32 PM

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Mar 11, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 11, 2025
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super-nit: After #28040, you can convert this to file-scope namespace by CTRL+. in Visual Studio (I believe it's the same in VS Code).

If it is converted, then new files will use file-scope namespaces more and more as people IMO copy old files to create new code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion , I have changed the file-scope namespace.

Comment thread src/Core/src/Platform/Android/ImageViewExtensions.cs
@jsuarezruiz jsuarezruiz added the area-controls-button Button, ImageButton label Mar 12, 2025
@jsuarezruiz

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

public void Issue25558VerifyImageButtonAspects()
{
App.WaitForElement("imageButton");
VerifyScreenshot();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pending snapshots on Mac and Windows. Already available in the latest build.

Example, Mac:
image

Could you commit the images?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have committed the image.


[Test]
[Category(UITestCategories.ImageButton)]
public void Issue25558VerifyImageButtonAspects()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is failing on Windows:

   at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2367
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2384
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 665
   at Microsoft.Maui.TestCases.Tests.Issues.Issue25558.Issue25558VerifyImageButtonAspects() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25558.cs:line 19
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have modified the test to resolve the failing.

@Shalini-Ashokan Shalini-Ashokan marked this pull request as ready for review March 13, 2025 06:46
@Shalini-Ashokan Shalini-Ashokan requested a review from a team as a code owner March 13, 2025 06:46
@Shalini-Ashokan

Copy link
Copy Markdown
Contributor Author

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?

Issue18242Test-diff

@jsuarezruiz

Copy link
Copy Markdown
Contributor

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?

Issue18242Test-diff

In that case, yes.

@Shalini-Ashokan

Copy link
Copy Markdown
Contributor Author

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?
Issue18242Test-diff

In that case, yes.

@jsuarezruiz, I have committed the failure image.

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/rebase

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/rebase

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/rebase

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/rebase

This was referenced Mar 11, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-button Button, ImageButton community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageButton dosen't scale Image correctly ButtonImage width not sizing correctly

8 participants