我想将一些子控件放置在我的 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/