Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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):

  • create a library project for the assets
  • mark the assets as resources to embed them into the generated assembly
  • reference the assets project from the other projects
  • reference the icons from the XAML code using the somewhat strange "pack" URI format.

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:

  • I've created a new library project "Assets" and added the image inside as "Content"
  • I've referenced this project from my main project

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

<Image Source="ms-resource://Assets/Files/Mushroom.png"></Image>
like image 998
Pragmateek Avatar asked Oct 01 '22 05:10

Pragmateek


1 Answers

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...

like image 128
Pragmateek Avatar answered Oct 11 '22 02:10

Pragmateek