views:

53

answers:

3

I need to display an image, which I've done without problems before, but today I decided to be tricky and use "add as link" instead. Well, now I get:

The file Images/hello.png is not part of the project or its 'Build Action' property is not set to 'Resource'.

Wait... its Build Action is set to Resource. I've seen a Silverlight solution that involves the usage of Merged Dictionaries to share files between Silverlight and WPF projects, but it's not clear to me that this would even apply to my WPF + Image issue.

Has anyone solved this problem before? I could make copies of all of the images, but that seems a little silly if I have a shared repository with clip art and the like.

+1  A: 

Dave,

I've just tried to add image as a link to plain WPF application. Build action is "Resource" (don't confuse with "Embedded Resource"). I've added it to the root, and refer to it as <Image Source="/file_name.jpg"/> - all works fine.

The message you have is it compile or runtime? If it's a runtime, how do you refer to the image? Do you see it in Reflector, when you open your assembly (it should be under Resources folder)?

Anvaka
Thanks, Anvaka. As my question states, I did set it to Resource (not Embedded Resource), and it's a design-time error. I can't even compile the code to test it.
Dave
BTW, I'll add it to the root instead, as you have done. We'll see if that does the trick!
Dave
Unbelievable. That worked. WTF is it not possible to put it in a folder, like I used to do? Another weird thing -- if I use my original approach, but put the image in an assembly other than the main application, it works. Weird. Anyhow, it's working now, I'm happy, so thanks a bunch for answering!
Dave
A: 

I have images in one assembly which I want to share into another. I've used Add as Link in my second assembly. In the project where the actual image files are located they are in a Resources\Images folder. In the project which links to those files the links are also in a Resources\Images folder. At runtime a XamlParseException claiming "cannot locate resource" is thrown.

My xaml which is referencing the image is in a UserControls folder.

In the project which actually contains the images the path ..\Resources\Images\Blah.png works fine as expected.

Opening the DLLs in Reflector makes it obvious that in the assembly with the linked images holds the images at the root level - the compiler is not respecting the folder location. So in the project with the linked files I have to use ..\Blah.png to find the resource.

Surely a bug in the compiler?

Pete Maher
A: 

Definitely a bug in MSBuild. See http://stackoverflow.com/questions/917285/linked-files-within-a-folder-structure

Pete Maher