我使用Xamarin Forms Labs获得以下Xaml。图像太小,文本居中。我试图让图像更大一些,但ImageHeightRequest属性似乎没有任何影响。我还尝试了几种StackLayout格式组合,例如StackLayout上的HorizontalOptions =“StartAndExpand”,以及元素。这导致按钮被压缩到左侧,并且不足以显示按钮的整个文本。有没有人知道如何用更大的图像实现这一点,并且一切都与左边对齐?我知道图像更大,因为我将其从Windows Phone移植到Xamarin,并且在Windows Phone上相同的图像更大。我也尝试使用常规的Xamarin Forms Image Button,它渲染相同大小的图像
<StackLayout Spacing="0" >
<Label>
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="My Label" ForegroundColor="#5C85FF" Font="Large"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<controls:ImageButton Text="Button 1" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image1.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ScanProductClicked" />
<controls:ImageButton Text="Button 2" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image2.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShopProductsClicked" />
<controls:ImageButton Text="Button 3" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image3.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShoppingListsClicked" />
<controls:ImageButton Text="Button 4" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image4.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="LogInClicked" />
<controls:ImageButton Text="Button 5" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image5.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="SettingsClicked" /> </StackLayout>
答案 0 :(得分:1)
您可以使用TapGestureRecognizer制作图像点击来解决此问题。要实现,请执行以下操作: http://www.c-sharpcorner.com/UploadFile/e04e9a/xamarin-forms-image-button-recipe/