【问题标题】:Xamarin Forms child controls inside buttonXamarin Forms 按钮内的子控件
【发布时间】:2015-11-28 20:34:30
【问题描述】:

我想在我的 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>

请帮帮我。

【问题讨论】:

    标签: xaml windows-phone-8 xamarin xamarin.forms


    【解决方案1】:

    您应该将所有内容包装到 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>
    

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

    【讨论】:

    • 我希望他们能够像 UWP、WPF 和 Silverlight 应用程序中的典型 XAML 一样进行这项工作。呃..
    【解决方案2】:

    您可以像这样在按钮中包含图像和文本,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      相关资源
      最近更新 更多