Home > database >  Grid Layout in .NET MAUI doesn't work as expected
Grid Layout in .NET MAUI doesn't work as expected

Time:06-10


I wanted to do specific layout for android screen. At the top I want to have two information labes (Box1 and Box2). Below them I want to have field which take rest of the screen (Box3). At the absolute bottom I want to have field with control buttons. I tried a lot of layout, but noone worked.
I'm using the latest release candidate version of .NET MAUI on windows 11 with latest Visual Studio Community 2022 (64-bit) - Preview in Version 17.3.0 Preview 1.1
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Calendar.MainPage">
         
<ScrollView
    BackgroundColor="Violet">
    <Grid
        RowDefinitions="50, 50, *, 50">
        <Label
            Grid.Row="0"
            Text="Box1"
            BackgroundColor="Red" />
        <Label
            Grid.Row="1"
            Text="Box2"
            BackgroundColor="Green" />
        <Label
            Grid.Row="2"
            Text="Box3"
            BackgroundColor="Yellow" />
        <Label
            Grid.Row="3"
            Text="Box4"
            BackgroundColor="Aqua" />
    </Grid>
</ScrollView>

</ContentPage>

And result is a bit different

enter image description here

Can anyone help me and tell me, what I'm doing wrong?

CodePudding user response:

If you remove the ScrollView it should work as you expect.

CodePudding user response:

Thank you. As I wrote it really works. Thank you anyway. Sometimes solution is easy as much as it can be. Thank you

The solution is: get rid unnecessary elements and use as the only layout Grid. It doesn't work, because there was as root element scrollView which makes the screen virtualy indefinite. So the solution is clear and simple.

  • Related