Serge P.
Serge P.

Reputation: 327

Refer an image resource from Universal App shared project

I just started work with winRT, shared projects etc. and faced with some problems. I want to put all of my resources (strings, images etc.) in one project (portable class library or shared project). When I put an image in PCL everything works fine in xaml by referencing with ms-appx:

<ImageBrush ImageSource="ms-appx:///Resources/Images/baby.jpg" Stretch="Uniform"/>

But when I put a string resource in PCL, I have following weird xaml behavior with ResourceDictionary:

http://postimg.org/image/ysbkvv6d7/

Ok. Then I decided to put every resources in Shared project. For this time it works perfectly with strings but fails with images: I couldn't get the right URI string in ImageSource of ImageBrush.

So the questions are:

  1. How can I add ResourceDictionary in PCL

  2. What is the correct URI format to reference image from shared project.

Thanks in advance!

Upvotes: 4

Views: 2207

Answers (1)

Bryan Stump
Bryan Stump

Reputation: 1439

To access an image your shared project file, just use the direct file path. The

<Image Source="Assets/ImageName.png"></Image>

Edited by @JerryNixon

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

To access an image in your PCL, use the longer syntax

<Image Source="ms-appx:///ProjectName/...path.../"/>

Upvotes: 12

Related Questions