3 Row Grid w/ Vertically Centered Children

From shared xaml code, we can not make sure the inside control also will show center vertically and horizontally.

Here is the sample code to explain that:

<Grid RowDefinitions="Auto, *, Auto">
    <StackLayout Grid.Row="0"
                    Orientation="Horizontal"
                    HeightRequest="200"
                    WidthRequest="300"
                    HorizontalOptions="Center"
                    VerticalOptions="Center"
                    BackgroundColor="Silver" >
        <Label Text="First label" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
    </StackLayout>

    <StackLayout Grid.Row="1" BackgroundColor="Aqua"
                    HeightRequest="200"
                    WidthRequest="300"
                    HorizontalOptions="CenterAndExpand"
                    VerticalOptions="CenterAndExpand">
        <Label Text="Second label" />
    </StackLayout>

    <StackLayout Grid.Row="2"
                    HeightRequest="200"
                    WidthRequest="300"
                    BackgroundColor="SeaShell"
                    Orientation="Horizontal"
                    HorizontalOptions="Center"
                    VerticalOptions="Center">
        <Label Text="Third Label" />
    </StackLayout>
</Grid>

The effect:

enter image description here

You will see that the first Grid if set HorizontalOptions and VerticalOptions for the inside Label, then it will show center vertically and horizontally.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top