22

I would like to assign a BitmapImage from my Resources.resx to an Image. Beforehand I saved a .png image to Resources.resx. This image is now located in "/Resources/logo.png".

After reading several SO posts and other articles I have this now:

logoImage.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/logo.png"));

Unfortunately it doesn't work. I don't know how to solve this.

I tried to replace the Pack-URI with the fullpath and it worked but I would like to use relative paths in order to use the same source on different machines on which the absolute path would be incorrect.

Can anyone help me out with this?

0

1 Answer 1

36

In order to make that Uri work, the file logo.png must be contained in a folder named "Resources" in your VS project (see first image), and its Build Action must be set to Resource (see second image).

VS Project

Build Action

This Resources folder is completely unrelated to Resources.resx. You may rename it to whatever you like.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.