user119039
user119039

Reputation: 13

Images in a WPF Custom Control Library

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?

Upvotes: 1

Views: 6256

Answers (2)

Drew Noakes
Drew Noakes

Reputation: 311345

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.

Upvotes: 1

Thomas Levesque
Thomas Levesque

Reputation: 292755

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"/>

Upvotes: 4

Related Questions