Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uri for bitmap in subfolder (c# wpf)

Tags:

c#

uri

bitmap

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?

like image 423
Gern Blanston Avatar asked Jun 10 '10 21:06

Gern Blanston


1 Answers

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);
like image 146
Eric Olsson Avatar answered Oct 12 '22 02:10

Eric Olsson