Xamarin表格 - 图像没有出现在Lumia上

时间:2017-11-09 08:10:47

标签: image xamarin.forms uwp

我实施了一个以UWP平台为目标的Xamarin应用程序。 我在PCL的Assets中添加了4张图片,并在每张图片上设置Build Action = Embedded Resource。 UWP项目中未添加任何图像。

如果我在我的笔记本电脑上运行该应用程序一切都很好,而当我在我的Lumia上运行相同的应用程序时,没有任何图像显示。我不明白为什么,因为应用程序与目标平台的唯一区别相同,我的笔记本电脑的x64 / x86和我的Lumia的ARM。(
我还尝试为每张图片设置Copy to output Directory = Copy Always,但没有成功。

2 个答案:

答案 0 :(得分:0)

你有没有试过另一个plaftorm(Droid,iOs?) 如文档中提到的那样:https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/,您需要:

1)使用自定义MarkupExtension从EmbeddedResource加载图像:

[ContentProperty ("Source")]
public class ImageResourceExtension : IMarkupExtension
{
 public string Source { get; set; }

 public object ProvideValue (IServiceProvider serviceProvider)
 {
   if (Source == null)
   {
     return null;
   }
   // Do your translation lookup here, using whatever method you require
   var imageSource = ImageSource.FromResource(Source);

   return imageSource;
 }
}

2)使用此自定义标记扩展并提供图像的完全限定名称(名称空间+名称)

<Image Source="{local:ImageResource MyProject.Assets.Images.beach.jpg}" />

答案 1 :(得分:0)

刚刚找到解决方案,禁用&#34;使用.NET Native工具链编译&#34;。 https://stackoverflow.com/a/37352400/2297037

您对可能的副作用有所了解吗?