Xamarin.Forms PCL无法显示图像

问题描述:

我正在学习Xamarin.Forms PCL。我想在页面上加载图像,我试图用uri加载图像,没关系。但我在项目中添加图片,这是行不通的。Xamarin.Forms PCL无法显示图像

<StackLayout Margin="0,20,0,0"> 
     <Image x:Name="img" Source="mario.jpg"/> 
     <Button x:Name="btnRotate" Clicked="btnRotate_Clicked" Text="Rotate" /> 
    </StackLayout> 

enter image description here

任何帮助表示赞赏。谢谢!

+0

不应''?你错过了一个“m” – apineda

+0

谢谢#apineda!我试过这个,但这不起作用 –

+1

你要从哪里加载图像?我在你的PCL以及你的Android项目中看到'mario.jpg'。如果您尝试从Android项目加载它:右键单击该文件,选择属性,并检查它是否为Android操作系统和IOS加载的Android操作设置为AndroidResource' –

不能包括在图像名称破折号或空格为Android兼容性

piotr-chrobot-276746.jpg重命名你的图像到别的东西,像piotrchrobot.jpg

enter image description here

https://developer.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_1_-_android_resource_basics/

不要忘记将生成操作设置为AndroidResource。

enter image description here

+0

我的图像mario.jpg仍然不显示 –

+0

也许,你可以分享一个github回购看看:) –

+0

我看到我的文件夹属性只读,是这个问题?和我试图删除只读属性,但不成功:( –