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:

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

<StackLayout Margin="20"  >

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

            <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()
        {
            InitializeComponent();

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

No result, the labels are still under each other.

Anyone who can help me out?
Thanks a lot,

Tagged:
Sign In or Register to comment.