Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using local images in WPF preview of Xamarin.Forms

Tags:

According to this documentation, it is possible to reference a local image with the same file name across different platforms in shared Xamarin Forms code.

There are instructions on where the image files should be located and what the build action should be set to for iOS, Android, Windows Phone and UWP projects.

Unfortunately, instructions are missing for the recently released WPF preview of Xamarin Forms.

Where should the local image files be placed, and what should the build action be set to in a WPF Xamarin Forms project?

like image 320
Anders Gustafsson Avatar asked Apr 12 '18 08:04

Anders Gustafsson


1 Answers

Set a build action of Content for your images, assumably in the Assets folder

enter image description here

FYI: There are 3 registered WPF image sources in Forms

  1. FileImageSourceHandler
  2. StreamImageSourceHandler
  3. UriImageSourceHandler

Forms WPF Image Source

Additional Info from @AndersGustafsson

  1. Build Action Content is the same build action as for Windows Phone and UWP platforms.

  2. It seems like you are required to copy the image file to the output directory for the image to be recognized by the WPF application. This is different from UWP, where copying is not required.

  3. It is OK to add the image file as a link in the WPF project. If I am not mistaken, this is not allowed in UWP.

like image 171
SushiHangover Avatar answered Oct 11 '22 12:10

SushiHangover