Three elements aligned horizontally in a vertically aligned Stacklayout

RHooglandRHoogland Member ✭✭

I am trying to get three elements (labels in my test) aligned horizontally, the rest of my page staying vertically aligned.
I tested it with three simple labels without success.
This is what I did:

A grid with 1 row and three columns, here is the beginning of my xaml

<StackLayout Margin="20"  >

            <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                    <RowDefinition Height="Auto"></RowDefinition>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                    <ColumnDefinition Width="200"></ColumnDefinition>

            <Label x:Name="lbl1" Text="bla1" Grid.Row="0" Grid.Column="0" HorizontalOptions="StartAndExpand"/>
            <Label x:Name="lbl2" Text="bla2" Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand"/>
            <Label x:Name="lbl3" Text="bla3" Grid.Row="0" Grid.Column="2" HorizontalOptions="End"/>

No result, the labels are still under each other.

Then I removed the grid in my xaml and added C#-code in the .c file. Here is the beginning of my file:

public PersonPage()

            Label lbl1 = new Label { Text = "blabla1" };
            Label lbl2 = new Label { Text = "blabla2" };
            Label lbl3 = new Label { Text = "blabla3" };
            StackLayout myStackLayout = new StackLayout
                Children =
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,

No result, the labels are still under each other.

Anyone who can help me out?
Thanks a lot,

Sign In or Register to comment.