[英]Xamarin.Forms : How to get and add swipe events on Android and ios?
[英]How to add an image to my Xamarin.Forms shared project's resources so that it can be used in both the Android and iOS projects?
I'm building a Xamarin.Forms app for Android and iOS and I want to add images to my Xamarin.Forms shared project so that they are displayed in both the Android and iOS app.
這就是我目前添加它們的方式:
這就是我在代碼中引用它們並將它們動態添加到 Grid 元素的方式:
但是當我運行應用程序(使用 Android 仿真器調試器)時,我看不到網格中加載的圖像。 我的 Output window 中出現以下錯誤:
[0:] 無法加載名為:{0}: Images\Blue-1.png 的圖像
[0:] FileImageSourceHandler:找不到圖像或圖像文件無效:文件:Images\Blue-1.png
我是否也需要將相同圖像的副本添加到 ModelT.Android 和 ModelT.iOS 項目的資源中? (我認為主要共享項目的全部意義在於我不必這樣做?)
共享項目中的任何圖像都需要設置為EmbeddedResource
,並且需要將完整路徑用於源。
var image = new Image
{
Source = ImageSource.FromResource("ModelT.Images.****Blue-1.png")
};
更多信息可以在嵌入式圖像部分的文檔中找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.