I need to put an image in the default view of a custom control. However, whenever I try to test the control it can't locate the image. I have tried to compile it as an embedded resource and just a plain resource in VS. Neither of these have worked. So is there a correct way to do this?
Asked
Active
Viewed 6,198 times
1
-
Thanks for all of your help. I was able to use the Pack URI scheme to get to properly reference the image I needed to add. – user119039 Jun 10 '09 at 19:39
2 Answers
4
That's probably because you specified the image path as a relative path. You should use the Pack URI Scheme to specify that the resource is in the current assembly. For instance :
<Image Source="pack://application:,,,/Images/MyImage.png"/>

Thomas Levesque
- 286,951
- 70
- 623
- 758
1
I have an open-source library that allows you to include country flags in your WPF application via a value converter. The flags images are stored as resources within the assembly.
It's available on NuGet:
Install-Package FamFamFam.Flags.Wpf
The source is up on GitHub:
https://github.com/drewnoakes/famfamfam-flags-wpf
You can take a look to see how the images are embedded and the Pack URI scheme is used.

Drew Noakes
- 300,895
- 165
- 679
- 742