xaml - 按钮内的 Xamarin Forms 子控件

标签 xaml windows-phone-8 xamarin 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>

请帮助我。

最佳答案

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

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

这个网格将像一个有子级的按钮一样。

关于xaml - 按钮内的 Xamarin Forms 子控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32368326/

相关文章:

c# - WPF8/C# - 将数据绑定(bind)到网格

mono - 如何为 AndroidGameView 启用抗锯齿 (4X MSAA)?

ssl - 在 httpClient 中使用 POST 时如何确保数据被加密

c# - 我们怎么知道元素在windows phone 8中是可视化的

ios - 如何更改 UIBarButtonItem 的上边距

c# - 在单个 WPF 控件中列出所有 Validation.Errors?

c# - APP.xaml 中带有事件的 XAML 外包数据模板

.net - WPF XAML - 带有 ItemSource 和子菜单项的 MenuItem

wpf - 为什么在即时更改数据时我的MVVM不起作用?

c# - 异步读写器储物柜