按钮内的 Xamarin Forms 子控件

Xamarin Forms child controls inside button

我想在我的 xamarin 表单中的按钮内放置一些子控件application.I尝试了以下代码,但子控件没有显示。

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

请帮助我。

您应该将所有内容包装到一个布局中,例如 Grid。然后将透明按钮放在网格上。像这样。

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

这个网格就像一个有孩子的按钮。

你可以像这样在按钮中添加图片和文字,

<Button BackgroundColor="Transparent" Image="updatesite.png" Text="Update Site and Settings" TextColor="Gray" ContentLayout="Top,0"/>