How to resize a button in Xamarin

Just Size parent View, for example if it's in a StackLayout, it'll be same size with parent.

   <Grid HeightRequest="120" WidthRequest="120" HorizontalOptions="Center">
            <Button Text="Hello!" BackgroundColor="Red"/>
        </Grid>

It'll be shown 120 x 120,

Because, Button's Default HorizontalOptions is Fill, VerticalOptions is Start. But some Controls like buttons, ignores Height or Width request and prefer to fill parent. Other elements in the same Layout effects button. Just resize parent of button and leave it.


  <StackLayout>
    <!--I am wider but shorter-->
    <Button Text="1" WidthRequest="100" HeightRequest="50"></Button>
    <!--I am narrower but longer-->
    <Button Text="2" WidthRequest="50" HeightRequest="100"></Button>
    <!--I fill the whole width. See also VerticalOptions-->
    <Button Text="3" HorizontalOptions="FillAndExpand"></Button>
  </StackLayout>

<StackLayout >
    <Button Text="1" WidthRequest="50" 
            HorizontalOptions="Center"></Button>
    <Button Text="2" WidthRequest="50" 
            HorizontalOptions="Center"></Button>
</StackLayout>

enter image description here


You can use HorizontalOptions attribute to make the width or height be as large as needed to contain the elements within it.

<Button  HorizontalOptions="Center"  Text="Retry" />