Aneesh.A.M
Aneesh.A.M

Reputation: 1148

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.

Upvotes: 11

Views: 8233

Answers (2)

jojobarcream
jojobarcream

Reputation: 589

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.

Upvotes: 16

Tushar patel
Tushar patel

Reputation: 3407

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"/>

Upvotes: 6

Related Questions