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.
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.
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With