Question Adding an Image to a WPF Form Using Image Control / Image from Resources

mhoney

New member
Joined
Oct 23, 2014
Messages
4
Programming Experience
10+
Hi,

Hoping you might be able to assist me with a question about setting the source property of an image control in WPF application to that of a stored png file in Resources.

I have added the image as a resource in Visual Studio 2013 and by selecting the image in the Image Control Properties it shows on the form correctly. When I run the application however, the image does not show?

If I set the image control source in the properties area to c:\Image.png the image will show at runtime but I wish to have the image stored and utilised from Resources not a direct path to a file on c:\.

I have a folder in the application called Resources and added the image using the Visual Studio 2013 Add Resource facility.

I you can point me in the right direction I would greatly appreciate it / I am sure it is something simple.

Thanks for your assistance.

Michael.
 
Hi,

I managed to work out the issue and thought be good to share the solution, should someone else ever have the same query. The steps I took were as follows:

Import the image into Visual Studio 2013 resources (as existing file)
Expand the resources folder in Solution Explorer
Click the image file that you added as a resource
Under Properties change the Build Action property to "Resource"

This fixed the issue immediately and the image now shows when I run the program. Also on the WPF form, the image control source property now correctly displays as Resources/Image.png

Thanks.

Michael.
 
Back
Top Bottom