tags:

views:

19

answers:

1

In my c#/WPF project, I added a jpg to the resources to embed into the exe file.

Now I want to use this jpg in an image tag, something like

<xmlns:prop="clr-namespace:MyProgram.Properties"
<Image Source="{Binding Source={StaticResource prop:LogoJpg}}"

My problem: it does not work. I got no idea, how to use the image. I could use files from the hdd, but I need the image to be embedded in the exe file.

A: 

First, add the image to your project, with a Build Action of "Resource" (not EmbeddedResource). For instance, I've added an image called "logo.jpg" to a folder called Images in my main project.

Then, in XAML, you use just use that resource as follows:

<Image Source="Images\logo.jpg" />

You can also use the pack syntax for the source:

<Image Source="pack://siteoforigin:,,,/Images/logo.jpg"  />

Hope this helps.

Wonko the Sane
I knew it should have been simple - thanks a lot!
Sam