tags:

views:

173

answers:

1

I have a wpf app where I'm using an image. To reference the image I use:

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/myIcon.png");
BitmapImage(uri)

If I add the png directly under the csproj file (with its properties BuildAction=Resource) then it works fine.

But I want to move it to a subfolder under the csproj. Another SO question asked about bitmaps\uri's (857732) and an answer linked to this msdn. So I tried :

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/Icons/myIcon.png");

But that did not work.

Any ideas?

A: 

If the image is in your solution (i.e., you are not referencing the image from another assembly), you should be able to use this syntax:

Uri uri = new Uri("pack://application:,,,/Icons/myIcon.png", UriKind.Absolute);

Or, you can use a relative Uri as follows:

Uri uri = new Uri("/Icons/myIcon.png", UriKind.Relative);
Eric