Search code examples
windows-8winrt-xaml

In WinRT XAML, how to reference images in outside/separate assembly/project?


Seems to be different in WinRT (Windows 8). Anyone figure it out yet?

My experiments.

Of course:

File Build Action == Content && Copy to Output Directory == Copy always

These don't seem to work:

<Image Source="Folder/file.jpg" />
<Image Source="/Folder/file.jpg" />
<Image Source="Namespace;Folder/file.jpg" />
<Image Source="Namespace;/Folder/file.jpg" />
<Image Source="pack://Namespace;Folder/file.jpg" />
<Image Source="pack://Namespace;/Folder/file.jpg" />

Out of desperation I tried:

File Build Action == Embedded Resource && Copy to Output Directory == Copy always

Still fail. Ugh!


Solution

  • <Image Source = "ms-appx:///<projectName>/<folderName>/<contentName>" />
    

    For example ...

    <Image Source = "ms-appx:///ClassLibrary1/Content/myimage.png" />
    

    See How to Reference Content for a bit more info.