Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms child controls inside button

I want to place some child controls inside a button in my xamarin form application.I tried the following code but the child controls are not showing.

 <Button>
<StackLayout Orientation="Horizontal">
  <Image Source="updatesite.png" HeightRequest="25" WidthRequest="25"/>
  <Label VerticalOptions="Center" Text="Update Site and Settings" FontSize="16"/>
</StackLayout>
</Button>

Please help me.

like image 489
Aneesh.A.M Avatar asked Sep 03 '15 06:09

Aneesh.A.M


2 Answers

You should wrap all the content into a layout such as Grid. Then place the transparent button onto grid. like this.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="25"/>
        <RowDefinition Height="25"/>
    </Grid.RowDefinitions>
    <Image Grid.Row="0" Source="updatesite.png" />
    <Label Grid.Row="1" VerticalOptions="Center" Text="Update Site and Settings" FontSize="16"/>
    <Button Grid.Row="0" Grid.RowSpan="2" x:Name="buttonDo" 
        BackgroundColor="Transparent" TextColor="Transparent"
    />
</Grid>

This Grid will act like a button that have chidren.

like image 197
jojobarcream Avatar answered Jan 28 '23 13:01

jojobarcream


You can have image and text in the button like this,

<Button BackgroundColor="Transparent" Image="updatesite.png" Text="Update Site and Settings" TextColor="Gray" ContentLayout="Top,0"/>
like image 26
Tushar patel Avatar answered Jan 28 '23 12:01

Tushar patel