Reputation: 19396
In a MAUI page, I am trying to put one button aligned to the left and the second button to the right. But I am not able to do it.
I am trying this:
<StackLayout>
<HorizontalStackLayout BackgroundColor="Yellow">
<Button HorizontalOptions="Start"
Command="{Binding ResgistrarEntradaCommand}"
ImageSource="cronoa.svg"/>
<Button HorizontalOptions="End"
Command="{Binding ResgistrarSalidaCommand}"
ImageSource="cronob.svg"/>
</HorizontalStackLayout>
</StackLayout>
With the background, I can see the that the HorizontlStackLayOut fill all the screen from left to right, but the buttons are not in the left.
According to the documentation, https://learn.microsoft.com/en-us/dotnet/maui/user-interface/layouts/horizontalstacklayout?view=net-maui-7.0, I think I should to get the expected behavior.
How could I place one button to the left and the second to the right?
EDIT: this is how it looks now:
EDIT 2: I have tried in this way, as recommended in a comment, using a StackLayout with HorizontalOptions as Fill:
<StackLayout BackgroundColor="Yellow" Orientation="Horizontal"
VerticalOptions="Start" HorizontalOptions="Fill">
<Button HorizontalOptions="Start" VerticalOptions="Start"
Command="{Binding ResgistrarEntradaCommand}"
ImageSource="cronoa.svg"/>
<Button HorizontalOptions="End" VerticalOptions="Start"
Command="{Binding ResgistrarSalidaCommand}"
ImageSource="cronob.svg"/>
</StackLayout>
I get the same result.
If I dont set the orientation of the StackLayout, then I get this result:
In this case I get one button to the left and another to the right, but I would like to have the same in the same row.
EDIT 3:
This is with a grid:
<Grid HorizontalOptions="Fill" BackgroundColor="Yellow" VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Button HorizontalOptions="Start" VerticalOptions="Start"
Command="{Binding ResgistrarEntradaCommand}"
ImageSource="cronoa.svg"/>
<Button HorizontalOptions="End" VerticalOptions="Start"
Command="{Binding ResgistrarSalidaCommand}"
ImageSource="cronob.svg"/>
</Grid>
Thanks.
Upvotes: 1
Views: 2220
Reputation: 89169
your Grid
attempt was a good start, but you are not specifying a Column
value so both buttons are placed in the same Column
<Grid HorizontalOptions="Fill" BackgroundColor="Yellow" VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Start"
Command="{Binding ResgistrarEntradaCommand}"
ImageSource="cronoa.svg"/>
<Button Grid.Column="1" HorizontalOptions="End" VerticalOptions="Start"
Command="{Binding ResgistrarSalidaCommand}"
ImageSource="cronob.svg"/>
</Grid>
Upvotes: 4