Xamarin在按钮内部形成子控件

Ane*_*A.M 8 xaml xamarin windows-phone-8 xamarin.forms

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

 <Button>
<StackLayout Orientation="Horizontal">
  <Image Source="updatesite.png" HeightRequest="25" WidthRequest="25"/>
  <Label VerticalOptions="Center" Text="Update Site and Settings" FontSize="16"/>
</StackLayout>
</Button>
Run Code Online (Sandbox Code Playgroud)

请帮我.

小智 13

您应该将所有内容包装到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>
Run Code Online (Sandbox Code Playgroud)

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


Tus*_*tel 5

您可以在按钮中添加图像和文字,

<Button BackgroundColor="Transparent" Image="updatesite.png" Text="Update Site and Settings" TextColor="Gray" ContentLayout="Top,0"/>
Run Code Online (Sandbox Code Playgroud)