Displaying images with build action set to 'content' within WPF

1.6k views Asked by At

I have a main project in WinForms and I display pictures within this project with build action set to 'content'. I got a WPF window to work within my WinForms project, the only thing that currently does not work is displaying an image with build action set to 'content' within my WPF window. If I change the build action to 'resource' I can display the images just fine. This does break the functionality in my WinForms project unfortunately.

So is there any way I can display an image within WPF with build action set to 'content'? Without breaking my WinForms project of course, because I show the same image both in WinForms and WPF.

EDIT: I found a solution, see my answer further down.

1

There are 1 answers

0
J. Doe On BEST ANSWER

What eventually did the trick for me was shown in this answer combined with this answer.

I chose solution 2a from here:

Image will be in a SubFolder called "Resources" and .exe file will be small

Source="pack://application:,,,/Resources/example.png"
Build Action = Content
Copy to output directory = Copy if newer

Then I did:

ImageSource imageSource = new BitmapImage(new Uri("pack://application:,,,/Resources/example.png"));
image.Source = imageSource;