Forum Visual Studio

Visual Studio 2017 - Where is ResourceId after making an image an Embedded Resource

I'm not sure if I'm posting to the right area, so please tell me if I haven't.

I'm currently trying to develop a Xamarin.Forms app for use on Android and iOS and are currently trying to display an image as a background.
I'm following a course and it states that when you change the properties of an image to "Embedded Resource", it should show the 'ResourceId'.

When changing the image to "Embedded Resource", nothing in the properties pane changes at all to show ResourceID.
When doing the same thing in Visual Studio for Mac, it shows the ResourceID (note: I can set the resource ID in Visual Studio for Mac and it will compile properly on the Windows VS, but it still doesn't show the ResourceID.

I've tried multiple projects, and can't get it to work. Am I maybe missing something?

Thanks heaps.


  • AndreiMungiuAndreiMungiu DKMember

    I have exactly the same problem, please help!

  • Been over a month and no solution yet... Gives me little hope it would do anytime soon... :neutral:

  • AyalaFuksAyalaFuks USMember

    I have exactly the same issus please help me!!!!!

  • fo0fo0fo0fo0 Member ✭✭

    I have also the same issue .Please hep us :(

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Beau-DeanAdams and others, Are you trying to set the Bacground image at Page level?

  • fo0fo0fo0fo0 Member ✭✭

    If I change the image file property Build Action to 'Embedded Resource' ,the ResourceID doesn't appear .
    This is the screenshot of my property pane

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    I have only set the BuildAction to AndroidResource or BundledResource and then just it at page level as,

    <ContentPage ... ... ...
          BackgroundImage="MyImage.png" >

    I have never used any ResourceId. Can you give excerpts from the course where this was used?

  • fo0fo0fo0fo0 Member ✭✭

    Thank you for your kind response.

    I'm using this method in code behind :
    public Images ()
    InitializeComponent ();
    //here must be ResourceID but it doesn't work with me
    image.Source = ImageSource.FromResource("MyXamarine_2.Images.background.jpg");


    On page level

            <Image Aspect="AspectFill" x:Name="image"/>
  • Og73Og73 Member

    Has this been resolved by anyone, I'm having the same issue...

  • This is happening to me too and it is driving me mad. Please someone help.

  • Found a fix!
    Not sure if it's the right one, but it's working for me. Described here:

    why it happens
    Basically, resources in the "regular" folder of a cross-platform app get sort of re-created inside the folder of the currently active platform, so any reference to a resource path that's not platform-specific might not work. This may be why they don't show a resourceID for images in the main or "regular" folder--because it's dynamically assigned, and if there's a value listed there, and the programmer hard-codes before launch, it may not work.

    They give the solution on the referenced page, but here it is specifically applied to my image needs. Basically you use a "compiler directive" (which I didn't know about) to dynamically assign the prefix for the resource ID. Here's how it works for me:

    public partial class MainPage : ContentPage
        #if __IOS__
            public string ResourcePrefix = "MyApp.iOS.";
        #elif __ANDROID__
            private string ResourcePrefix = "MyApp.Droid.";
            private string ResourcePrefix = "MyApp.";  //note: this part isn't working to get the image in the preview
        private string ImageFileName = "flower.jpg";
        public MainPage()
            imageNameDefinedInXaml.Source = ImageSource.FromResource(ResourcePrefix + ImageFileName);

    Two notes:

    • The compiler directive if-else flow ends with just the app name, my attempt to get the image to appear in the Xaml Preview window. It didn't work. Just included here in case anyone else can figure it out.
    • My file is actually in a folder called "Images," so according to the referenced documentation page, the variable ImageFileName should require that as a prefix, and as such, be defined like this: "Images.flower.jpg" But in my experience (as of late May 2018), adding that prefix makes it fail. Just the raw filename seems to work no matter the sub-directory. YMMV.
  • That fix doesn't work!

    I neglected to test it on iOS and Android. Shucks.

    This however did work for me:

  • UGH now that one didn't work.

    This is working for me right now:

    using System.Linq;
    using System.Reflection;
    using System.Diagnostics;
    using System;
    namespace Helpers
        public class EmbeddedSourceror
            public static Xamarin.Forms.ImageSource SourceFor(string pclFilePathInResourceFormat)
                var resources = typeof(EmbeddedSourceror).GetTypeInfo().Assembly.GetManifestResourceNames();
                var resourceName = resources.Single(r => r.EndsWith(pclFilePathInResourceFormat, StringComparison.OrdinalIgnoreCase));
                Debug.WriteLine("EmbeddedSourceror: resourceName string is " + resourceName);
                return Xamarin.Forms.ImageSource.FromResource(resourceName);

    This is an amalgalm of code found in the above link as well as this post:

    edited October 2018

    I had this same issue. I resolved this by the following steps

    Step 1 : Right click on the image file, go to properties and set the build action to "Embedded Resource"
    Step 2 : ImageSource.FromResource("DLLName.FileName.ImageName.jpg");

             e.g., Say my project name is PCLBasics and image file placed inside folder called "Images"  
            so,  ImageSource.FromResource("PCLBasics.Images.background.jpg");
  • EKKYEKKY Member

    I believe I am in the same class as some of you guys...
    I think the solution is this (from stackoverflow, 30850510):

    Put background.jpg into YOUR_PROJ_NAME.Android/Resources/drawable
    Set Build Action to AndroidResource
    Use instead

    image.Source = ImageSource.FromFile("background.jpg");
  • Akash_VAkash_V Member

    The embedded resource id is : ApplicationName.Folder/foldersName.ImageNameWithExtension

    So, the code for Example.sln having a folder Images with background.jpg image as an embedded resource, would be:

    Image.Source = ImageSource.FromResource("Example.Images.background.jpg");

    Hope this helps :)

Sign In or Register to comment.