0

I implemented a Xamarin App with UWP Platform as target. I added 4 images in the Assets of PCL and set Build Action = Embedded Resource on each. No image has been added on UWP project.

If I run the app on my laptop everything works great, instead when I run the same app on my Lumia no image shows up. I don't understand why, since the app is the same with the only difference of Target Platform, x64/x86 for my laptop and ARM for my Lumia.

I have also tried to set Copy to output Directory = Copy Always for each image, but without success.

user2297037
  • 1,167
  • 2
  • 14
  • 34

2 Answers2

0

Have you tried in another plaftorm (Droid, iOs?) Like mentionned in the documentation: https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/, you need to:

1) Use a custom MarkupExtension to load image from 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) Use this Custom Markup Extension and provide the fully qualified name of your image (namespace + name)

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

Rudy Spano
  • 1,379
  • 10
  • 13
  • I can't test that functionality on the other platforms now. Yes I did that and in fact it works if I run the app on my laptop... – user2297037 Nov 09 '17 at 09:04
  • Just to be sure. Is your image a real jpg? (Not a png renamed with jpg). I've seen strange behavior on this kind of contexts. Perhaps you could test with a png image? – Rudy Spano Nov 09 '17 at 13:01
  • Just posted the solution. Thank you for your help. – user2297037 Nov 09 '17 at 13:13
0

Just found the solution, disable "Compile with .NET Native tool chain". https://stackoverflow.com/a/37352400/2297037

Do you know something about possible side effects?

user2297037
  • 1,167
  • 2
  • 14
  • 34