0

I have a WPF application, in which I want to insert an image. It shows up just fine in the design, but once I run the program nothing is displayed. The image is imported and stored using Project > Properties > Resources.resx and is located in the folder "Resources" as you can see in the screenshot in the bottom. The XAML code is quite simple:

<Image 
    Source="/Resources/warning_icon_32x32.png" 
    Width="32" 
    Height="32" 
    HorizontalAlignment="Left" />

Why does this not work? As you can see below, it works fine in the designer.

Image shown in the designer

Image location in project

EDIT

If I use the full path of the image (i.e. C:\...) then it works. However this would break as soon as it was opened on a different PC, so it's hardly a solid solution. It it interesting though...

Jakob Busk Sørensen
  • 5,599
  • 7
  • 44
  • 96
  • Make sure the image file is part of your Visual Studio project, located in a folder named Resources. Also set its Build Action to Resource. – Clemens Jan 24 '18 at 09:45
  • It was the build action which was the issue (see also this post: https://stackoverflow.com/questions/12690774/assign-bitmapimage-from-resources-resx-to-image-source/12693661#12693661) – Jakob Busk Sørensen Jan 24 '18 at 09:48
  • This may also be helpful: https://stackoverflow.com/a/15008178/1136211 – Clemens Jan 24 '18 at 09:51

0 Answers0