maui
maui copied to clipboard
Unexpected result with MaximumWidthRequest on a Label on Android
Description
MaximumWidthRequest on a Label on Android sometimes gives unexpected result. If you use in combined with HorisontalOptions=Fill you could get extra empty lines, and the text is wider than the maximum width. If you have value than is larger than the screen the Label will stretch outside the screen.

Compare this with Windows which I think behaves correctly:

Steps to Reproduce
- Create a new MAUI app.
- Update MainPage.xaml width this:
<ScrollView>
<VerticalStackLayout Padding="8">
<Label Text="MaximumWidthRequest: 200, HorizontalOptions: Start" />
<Rectangle MinimumHeightRequest="4" WidthRequest="200" HorizontalOptions="Start" BackgroundColor="#FF99FF" />
<Label
Text="one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five"
BackgroundColor="#9999FF"
HorizontalOptions="Start"
MaximumWidthRequest="200"
/>
<Label Text="MaximumWidthRequest: 200, HorizontalOptions: Fill" Margin="0,30,0,0" />
<Label
Text="one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five"
BackgroundColor="#9999FF"
HorizontalOptions="Fill"
MaximumWidthRequest="200"
/>
<Label Text="MaximumWidthRequest: 2000, HorizontalOptions: Start" Margin="0,30,0,0" />
<Label
Text="one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five"
BackgroundColor="#9999FF"
HorizontalOptions="Start"
MaximumWidthRequest="2000"
/>
</VerticalStackLayout>
</ScrollView>
- Run the application on Android.
Link to public reproduction project repository
https://github.com/pekspro/MauiIssues/tree/10552_Unexpected_result_with_MaximumWidthRequest
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows, I was not able test on other platforms
Affected platform versions
Windows 10.0.17763.0, Android 11
Did you find any workaround?
No response
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I've updated sample application to .NET 7. The same issue remains.
I got some problems with MaximumWidthRequest too.
I have a maximum width of 650 on my <Grid> (inside a <ScrollView>) because I don't want my <Entry> to fill all the screen because it looks ugly. I don't get why it's ok on tablet but on phone, it seems like the maximum width is taken as the requestWidth.
My problem is that on Android Phone, it feels like WidthRequest takes MaximumWidthRequest. My content goes out of the screen.
See the screenshot below

If I remove the maximum width, here is how it looks (and how it should looks with MaximWidthRequest)

The problem still exist on the latest .NET 7 released the 8th november 2022
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Android 13.0-API33 and iOS 16.4 with below Project: 10552.zip
Android:
iOS: