Xamarin Forms child controls inside button
Asked Answered
B

2

11

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.

Bally answered 3/9, 2015 at 6:23 Comment(0)
L
16

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.

Laughable answered 6/9, 2015 at 15:7 Comment(1)
I wish they would have made this work like typical XAML in UWP, WPF, and Silverlight apps. ugh..Orange
R
6

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"/>
Rowena answered 4/8, 2016 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.