2017-08-08 28 views
1

我正在學習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

不應'<圖像X:名稱= 「IMG」 源= 「mario.jpg」/>'?你錯過了一個「m」 – apineda

+0

謝謝#apineda!我試過這個,但這不起作用 –

+1

你要從哪裏加載圖像?我在你的PCL以及你的Android項目中看到'mario.jpg'。如果您嘗試從Android項目加載它:右鍵單擊該文件,選擇屬性,並檢查它是否爲Android操作系統和IOS加載的Android操作設置爲AndroidResource' –

回答

2

不能包括在圖像名稱破折號或空格爲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

我看到我的文件夾屬性只讀,是這個問題?和我試圖刪除只讀屬性,但不成功:( –