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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With