views:

219

answers:

2

I'm just learning WPF. I'm using VS 2008. I've added an Image control to my XAML, and I added a GIF file to the project. If I use the XAML Designer's property panel to set the image's Source property, the drop-down list for the Source property contains the following:

C:\Sample Project;component/pinHorizontal.gif

There are several problems with this:

  1. My project, named "Sample Project," is not in the root of my drive.

  2. Why is ";component" in there?

If I select this value as given, I get the error "Property value is not valid" (yeah, no kidding).

If I go into the XAML source and set the Source property manually, like so:

<Image Name="PinImage" Source="pinHorizontal.gif"/>

The XAML Designer gives me this error:

"The file pinHorizontal.gif is not part of the project or its 'Build Action' property is not set to 'Resource'."

Why is this task so difficult? How do I assign an image source?

+1  A: 

Right click on the image file(pinHorizontal.gif) in the SolutionExplorer, Go to properties, here is the 'Build Action' property, you need to set it to 'Resource'. Hope it helps!!

viky
Thanks, but I already did that.
elmonty
+1  A: 

Have a read through this article - though be warned it's not particularly light reading :-)

I suspect what you want for your image path is pack://application:,,,/pinHorizontal.gif. if your image is set to a BuildAction of Resource, this will work fine.

Dan Puzey
The WPF is undoubtedly powerful and productive -- but why did they have to make so many of its conventions and syntaxes so complex?
elmonty
With great power comes great confusion ;-)
Dan Puzey