Xamarin表示图像未显示 [英] Xamarin Forms image not showing
问题描述
我有一个Xamarin Forms(2.0)Android应用程序,我正在尝试显示图像。我有一个名为 icon-pages-r1.png
的图标,我试图使用以下代码显示:
I have a Xamarin Forms (2.0) Android app where I'm trying to show an image. I've got an icon called icon-pages-r1.png
which I'm trying to show using the following code:
<Image Source="icon-pages-r1.png" />
但是图像没有显示。当我将源更改为 Icon.png
(默认的Xamarin图标)时,它确实有效。
The image isn't showing though. When I change the source to Icon.png
(the default Xamarin icon) it does work.
图像是一个半透明的PNG(因此中间是彩色图标,周围是透明的),它是46x46,在Windows中,它显示为项目类型PNG文件。我尝试在Paint中打开图像并重新保存它(这会破坏透明度),但这也不起作用。图像的构建操作
是 AndroidResource
,复制到输出目录
设置为不要复制
。
The image is a semi-transparent PNG (thus a colored icon in the middle and transparent around it), it's 46x46 and in Windows it shows fine as item type PNG File. I tried opening the image in Paint and re-saving it (which kills the transparency) but that doesn't work either. The Build Action
for the images are AndroidResource
with Copy to Output Directory
set to Do not copy
.
有谁知道为什么我无法将此图像显示在我的应用程序?
Does anyone know why I can't get this image to show in my app?
推荐答案
您不能在Xamarin Android的图像名称中使用连字符。摆脱连字符(在文件名和图像参考中),你将被设置。
You can't use hyphens in image names for Xamarin Android. Get rid of the hyphens (in both the file name and the Image reference) and you'll be set.
这篇关于Xamarin表示图像未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!