Width calculation in the compatibility ButtonRenderer is broken #10473
Labels
area-controls-button
Button, ImageButton
area-layout
StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter
migration-compatibility
Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert
platform/windows 🪟
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
Milestone
Description
I have tried to migrate my project from Xamarin.Forms to MAUI. I have a custom button with some additional properties that uses a custom renderer in Xamarin.Forms. Everything works perfectly there. I was happy to learn that I can register a compatibility renderer in MAUI without any significant modifications.
However, MAUI renderer behaves differently than the Xamarin.Forms one. It works fine on Android but it sets completely incorrect width on Windows so the button has just a few pixels and its text is not visible. This bug complicates the migration from Xamarin.Forms.
I have prepared a repro project. It contains a line with buttons that should simulate a custom toolbar. First three buttons uses custom renderer. In the repro project, the renderer is empty. It just inherits from ButtonRenderer in MAUI and does nothing more.
Screenshot of the result - first three buttons are displayed incorrectly:
Screenshot of the result of you remove AddCompatibilityRenderer line from MauiProgram.cs - all buttons are displayed correctly:
I have found out that the following conditions are required for the bug: 1) a compatibility renderer for Button is used, 2) a width is set by WidthRequest, or MinimumWidthRequest, 3) the buttons are placed inside a Grid.
It seems that the bug is so specific that it is not worth bothering with it. Nevertheless, I know from my own experience that, because of the very specific conditions, it took me quite a lot of time to find out why some buttons are rendered correctly and some incorrectly in my app after migrating to MAUI. There is not much chance that the bug will be fixed but I still think it is useful to fill out the issue for it so that it would be at least documented so the other developers migrating from Xamarin.Forms would know what causes it and what workarounds are available for fixing it.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/holecekp/MauiBugButtonRenderer
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 10
Did you find any workaround?
There are more things that can be done but they are not always possible or not always leads to the desired design:
Relevant log output
No response
The text was updated successfully, but these errors were encountered: