Answered Set image source from another project

  • Wednesday, September 19, 2012 10:31 PM
     
      Has Code

    In Windows RT, I can set an image source to a file in the project like this:

                image.Source = new BitmapImage(new Uri("ms-appx:///Images/Koala.jpg"));

    Is it possible to set the Uri to a file in another project in the solution? In Silverlight, I was able to do something like this for a image in a different project named CommonLibrary.

                img.Source = new BitmapImage(new Uri("/CommonLibrary;component/Images/Koala.jpg", UriKind.Relative));

    Is there something equivalent I can use in Windows RT?

    • Edited by Richard.SF Wednesday, September 19, 2012 10:34 PM
    •  

All Replies

  • Thursday, September 20, 2012 5:32 AM
    Moderator
     
     Answered

    in windows store apps, you could use ms-appx:///,

    firstly, you could add CommonLibrary reference into your project, and then set image source:

    image.Source = new BitmapImage(new Uri("ms-appx:///CommonLibrary/Images/Koala.jpg"));


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked As Answer by Richard.SF Thursday, September 20, 2012 6:24 PM
    •  
  • Thursday, September 20, 2012 6:23 PM
     
     

    Thanks, it worked. However, I could only make it work if I put the image files in a Windows Store Class Library project. It isn't working if I use a Portable Class Library project. I want to use a Portable Class Library project that can be accessed from both a Windows Store project and a Windows Phone 8 project.

    I'll mark this answered and start a new thread concerning sharing files between WP8 and Win8 projects.