Pragmateek
Pragmateek

Reputation: 13374

Best way to share assets like images between projects

I'd like to share some assets like icons between multiple WinRT projects.

With WPF this was a no-brainer (well almost):

What's the best way of sharing them with Windows Runtime?

Is there such a resource embedding and sharing capability, or any other solution?

If no I guess I could add them to every project with "Copy as link" but I hope there is a clean way.

EDIT: I've started to do it naively like I would in a WPF project:

But I can't reference the image with the new URI format:

<Image Source="ms-resource://Assets/Files/Mushroom.png"></Image>

Upvotes: 5

Views: 2357

Answers (2)

Dave Enstrom
Dave Enstrom

Reputation: 113

It is very simple. Right click on the folder where you want the images (e.g., an Assets folder in the new Project) and the select "Add/Existing Item". Then select the images that you need and be sure to change the "Add" button, to "Add as Link". Done.

Upvotes: 0

Pragmateek
Pragmateek

Reputation: 13374

So finally I got the correct result.

Here is the full process:

  • create your library project, add your image and set its build action as "Content"
  • reference the library from your main project

To reference the image itself you must:

  • use the "ms-appx" schema, not "ms-resource" as you might find on Google
  • specify an absolute path with /// not //

    <Image Source="ms-appx:///Assets/Mushroom.png">

And above all don't trust the Visual Studio designer:

  • when you get it right it may not display the image
  • when you get it wrong it may display it (from a previous success) but at runtime you'll get nothing!

Hope this helps...

Upvotes: 4

Related Questions