Reputation: 1798
I am trying to reference images stored in a project folder
File path is SolutionName/ProjectName/Media/someImage.png
Properties of the images in the folder are
If I hardcode a test it works like:
var imageName = "C:/Test/TestImage/file.png";
But if I try something like:
var imageName = @"/ProjectName;component/Media/someImage.png"
it does not work! How can I reference the folder in the project in C# WPF application VS2012? Thanks!
Upvotes: 1
Views: 545
Reputation: 4417
if you have image folder like this:
ProjectName/bin/Images/yourImage.jpg
then you can use image like this:
picture.ImageLocation = @"Images\yourImage.jpg";
and check this
or you can make easier by using :
Properties.Resources.ImageName
if you imported image into resources folder inside you project
Upvotes: 1
Reputation: 30498
From the MSDN on Pack Uri's, when you are trying to reference a resource in code, you either need to fully qualify the Uri
:
var imageName = new Uri("application://,,,/ProjectName;component/Media/someImage.png");
or you need to specify a relative Uri
:
var imageName = new Uri("/ProjectName;component/Media/someImage.png", UriKind.Relative);
Upvotes: 2