pumpkinszwan
pumpkinszwan

Reputation: 1352

How do I use an image from another project in my XAML?

I am building a solution (Windows Phone app) with multiple projects; one of those projects is for "branding" - it contains some specific code as well as images, and the idea is that this project can be swapped out for different branding.

My app pages are in the main project, and I want to display images stored in the 2nd project in the main app's UI.

My projects compile and have the correct dependencies, etc. But my images don't show in the UI. I'm not sure how I'm supposed to reference them.

This is how the images are coded in the XAML when the images are stored in the main project - this works perfectly:

<Image Source="/MainProject;component/ThisTeam/Trophy.png"/>

However, I want to store the images in my secondary project but use them in my primary project, so the following DOESN'T work (the XAML is from MainProject):

<Image Source="/SecondaryProject;component/Images/Soccer.png"/>

Build type on the images is set to content, however I have tried Resources and other settings. Since the images work when stored in the main project I assume it's something other than that that is the issue.

My main project uses code from the secondary project, so my reference to that project works correctly.

Am I doing this the wrong way? Is it even possible to achieve what I'm trying to?

Upvotes: 5

Views: 2952

Answers (1)

pumpkinszwan
pumpkinszwan

Reputation: 1352

OK, I have resolved this issue.

In my fiddling I had removed the reference to one of my projects - but due to some classes with matching names the solution was still compiling and running!

And also, as Alastair noted, I needed to change the images to a Resource content type (I'm not sure why, as they work with the Content type when in the same project as the XAML code).

So the XAML I posted in my question was correct - but only if the projects are referenced correctly and the content type is set to Resource.

Upvotes: 2

Related Questions