图像未使用 XAML 以 Xamarin 形式显示? [英] Image not displaying in Xamarin forms using XAML?
问题描述
我想使用 XAML
在我的 Xamarin 表单项目中显示一个图像,但没有显示.这是代码:
I want to display an Image in my Xamarin forms project using XAML
but is is not displaying.
This is the code:
<Image x:Name="myimage" Source="logo.jpg"/>
我已将 myimage 的构建操作设置为 embedded resource
.我也试过这个
I have set myimage's build action to embedded resource
. I also tried this
<Image x:Name="myimage" Source="MyXamarinProject.logo.jpg"/>
其中 MyXamarinProject
是我的命名空间.但两者都不起作用.这里有什么问题?
Where MyXamarinProject
is my namespace. But both not working. What is wrong here?
推荐答案
为避免降低应用程序性能或在不同屏幕分辨率上显示图像的问题,推荐的方法是将每个图像添加到每个平台特定的文件夹中:
The recommended way to avoid decreasing application performance or problems displaying the images on different screen resolutions is adding each image on each platform specific folder:
Android:项目 -> 资源 -> Drawable(或每个分辨率的 drawable 文件夹 (-hdpi,-xhdpi...))
Android: Project -> Resources -> Drawable (or each resolution drawable folder (-hdpi,-xhdpi...))
iOS:您可以为每个图像创建资产目录或使用项目 -> 资源文件夹.
iOS: You can create an asset catalog for each image or use Project -> Resources folder.
然后,在 XAML 文件上使用图像名称.无需代码.
And then, use the image name on XAML file. No code needed.
这篇关于图像未使用 XAML 以 Xamarin 形式显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!