Search code examples
xamlwindows-phone-8xamarinxamarin.forms

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.


Solution

  • 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.