Assign BitmapImage from Resources.resx to Image.Source?

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?


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.