Skip to content

[ImageButton][Android] Padding is incorrect after IsVisible is changed #18001

@haavamoa

Description

@haavamoa

Description

Hello, and thank you for this awesome framework.

I've noticed a bug where ImageButtons for Android does not correctly set their Padding. I first thought it happened every time you draw a ImageButton, but that was not the case. It happens whenever you change the IsVisible property, which in many cases people are I presume.

In the follow example I have a ImageButton with the dotnet_bot as source and a red background. I've set the Padding to 50, which should make the bot smaller inside the button. This works the first time the app loads, but once I change the IsVisible (using the Switch) it ignores the Padding.

Screen.Recording.2023-10-13.at.13.56.55.mov

Steps to Reproduce

  1. Clone this repository.
  2. Select Android
  3. Run the code
  4. Observe the ImageButton has the correct padding once it loads.
  5. Observe the ImageButton not having the correct padding when you tap the Switch.

Link to public reproduction project repository

https://github.com/haavamoa/MauiApp/tree/task/hmo-imagebutton-padding-android

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

The way to get around this the issue where IsVisible is flipped is to make sure to update the padding after the IsVisible has changed:

Here is our fix, where we ship a wrapping ImageButton class.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-buttonButton, ImageButtonmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions