HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Storing WPF Image Resources

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
storingresourceswpfimage

Problem

For a WPF application which will need 10 - 20 small icons and images for illustrative purposes, is storing these in the assembly as embedded resources the right way to go?

If so, how do I specify in XAML that an Image control should load the image from an embedded resource?

Solution

If you will use the image in multiple places, then it's worth loading the image data only once into memory and then sharing it between all Image elements.

To do this, create a BitmapSource as a resource somewhere:




Then, in your code, use something like:




In my case, I found that I had to set the Image.png file to have a build action of Resource rather than just Content. This causes the image to be carried within your compiled assembly.

Context

Stack Overflow Q#347614, score: 521

Revisions (0)

No revisions yet.