Anyone know how to position 3 buttons in StackLayout
with equal width? I have it working with Grid
with
<Grid x:Name="MyGrid" Grid.Row="0" BindingContext="{x:Reference Name=Button1}" HeightRequest="{Binding Width}">
I would like to find a way to show 3 buttons on same line with same width equally without a Grid
For example all 3 buttons of equal length fitting across horizontally in StackLayout
[ Button 1 ] [ Button 222 ] [ Button 333333 ]
Still using Grid, just specify width of columns in percent (col spacing set for fun):
<Grid
ColumnDefinitions="33.33*, 33.33*, 33.33*"
ColumnSpacing="8"
HorizontalOptions="FillAndExpand">
<Button Text="1" Grid.Column="0" HorizontalOptions="FillAndExpand"/>
<Button Text="2" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Button Text="3" Grid.Column="2" HorizontalOptions="FillAndExpand"/>
</Grid>
Updated: use one-line ColumnDefinitions property in Xamarin.Forms 4.8
RelativeLayout:
<RelativeLayout HorizontalOptions="FillAndExpand">
<Button Text="Button 1" RelativeLayout.XConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=.0000,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,Factor=.3333,Constant=0}"/>
<Button Text="Button 222" RelativeLayout.XConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=.3333,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,Factor=.3333,Constant=0}"/>
<Button Text="Button 333333" RelativeLayout.XConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=.6666,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,Factor=.3333,Constant=0}"/>
</RelativeLayout>
StackLayout:
<StackLayout Orientation="Horizontal">
<Button x:Name="button1" Text="Button 1"/>
<Button Text="Button 222" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
<Button Text="Button 333333" WidthRequest="{Binding Path=Width, Source={x:Reference button1}}"/>
</StackLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With