【发布时间】:2020-05-25 14:57:02
【问题描述】:
我正在尝试使用带有图像而不是文本的按钮。我尝试使用带有 ImageSource 和 ImageButton 的 Button。既不显示图像,也只显示一个灰色矩形。我直接从 ButtonDemos 中的 ImageButtonDemoPage.xaml 复制了 XAML,还从文档中复制了用于在 Button 上使用图像的 XAML。我展示了下面的代码以及结果的屏幕截图。 我在 Resources/drawable 文件夹以及 Resources/drawable-hdpi 文件夹中有图像,如第二个屏幕截图所示。所有图像的构建操作都设置为 AndroidResource。 我已经没有什么想法可能出问题了。任何帮助,将不胜感激。 '''
</controls:UpcomingPaymentsView>
<ScrollView HorizontalOptions="CenterAndExpand">
<!--<Button>
<Button.ImageSource>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="iOS, Android" Value="MonkeyFace.png" />
<On Platform="UWP" Value="Assets/MonkeyFace.png" />
</OnPlatform>
</Button.ImageSource>
</Button>-->
<ImageButton Source="MonkeyFace.png"
WidthRequest="72"
HeightRequest="72"
FlexLayout.AlignSelf="Center"
FlexLayout.Grow="1"
Aspect="AspectFit">
</ImageButton>
</ScrollView>
</StackLayout>
【问题讨论】:
-
首先,请在
ImageButton中设置Aspect="Fill",如果它可以正确显示图像。然后,我的Xamarin.Formsnuget 包版本是 4.5.0.495,它可以正确显示图像。这是我的测试图像和运行结果。 imgur.com/a/9edlgE2 -
我将 Xamarin.Forms 包更新到最新版本,仅此一项似乎就解决了问题。我已经为 Aspect 使用了各种值,并且似乎一切正常。谢谢!
-
我会移动cmets来回答。请接受它作为答案,它将帮助其他有类似问题的人。
标签: xamarin.forms