Xamarin 表单图像未显示 [英] Xamarin Forms image not showing

查看:28
本文介绍了Xamarin 表单图像未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 中打开图像并重新保存它(这会破坏透明度),但这也不起作用.图像的 Build ActionAndroidResourceCopy to Output Directory 设置为 Do not copy.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆