question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaximumWidthRequest property behaves differently in Windows and Android

See original GitHub issue

Description

Inner Grid has a MaximumWidthRequest of 600, and is placed inside an outer Grid with a blue background.

On Windows it looks as desired: image

Shrink the window and it’s still fine: image

On Android it is wrong: image

Steps to Reproduce

New project.

This goes inside the ContentPage:

    <Grid BackgroundColor="Blue">
        <Grid MaximumWidthRequest="600" BackgroundColor="White">
            <ScrollView>
                <VerticalStackLayout 
                    Spacing="25" 
                    Padding="30,0" 
                    VerticalOptions="Center">

                    <Image
                        Source="dotnet_bot.png"
                        SemanticProperties.Description="Cute dot net bot waving hi to you!"
                        HeightRequest="200"
                        HorizontalOptions="Center" />

                    <Label 
                        Text="You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday; and my first task is to assure my dear sister of my welfare, and increasing confidence in the success of my undertaking."
                        SemanticProperties.HeadingLevel="Level1"
                        FontSize="32"
                        HorizontalOptions="Center" />

                    <Label 
                        Text="Welcome to .NET Multi-platform App UI"
                        SemanticProperties.HeadingLevel="Level2"
                        SemanticProperties.Description="Welcome to dot net Multi platform App U I"
                        FontSize="18"
                        HorizontalOptions="Center" />

                    <Button 
                        x:Name="CounterBtn"
                        Text="Click me"
                        SemanticProperties.Hint="Counts the number of times you click"
                        Clicked="OnCounterClicked"
                        HorizontalOptions="Center" />

                </VerticalStackLayout>
            </ScrollView>
        </Grid>
    </Grid>

Version with bug

Release Candidate 3 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

Bind MaximumWidthRequest to a view model readonly property that returns Min(600, screenVirtualWidth).

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:9

github_iconTop GitHub Comments

2reactions
Sebastian1989101commented, Apr 9, 2023

In my application’s case, the MaximumWidthRequest property works as desired on Android, but on iOS and Mac Catalyst it is ignored completely. E.g. for an item taking the full screen width, setting MaximumWidthRequest=100 limits the width to 100 only on Android, on Mac and iOS nothing happens when setting that property; I can only limit it for iOS / Mac with WidthRequest=100.

I can confirm this… It’s so annoying to design your app around MAUI bugs instead around your desired goal…

0reactions
MV10commented, Aug 16, 2023

Edit: I see this has been fixed for Button in v8. For a Button, it works on Windows but not Android…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Untitled
SearchBar centering inconsistency on Android with MaximumWidthRequest … ... in xamarin forms MaximumWidthRequest property behaves differently in Windows …
Read more >
Build accessible apps with semantic properties - .NET MAUI
On Android, this property behaves slightly differently depending on the control it's attached to. For example, for controls without text ...
Read more >
c# - How do I access and change properties of a control ...
1 Answer 1 ... To be honest, you should think clearly about interface design. On mobile, the interface is not large, if you...
Read more >
.NET MAUI Tutorial for Beginners - Build iOS, Android, macOS ...
NET MAUI to build apps for iOS, Android, macOS, and Windows. ... https://docs. microsoft.com/learn/paths/build-apps-with-dotnet-maui/?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found