I have a WPF control hosted in Windows Forms and I would like to access it’s resources, specifically images. What is the best way to do that?
I was thinking of using a ResourceDictionary, but I’m not sure how I can access it from within a Windows Form.
This is a standalone WPF control, in a DLL? There are two ways that the resources can be embedded… as part of a .resources file (e.g. the Project’s “Resoruces” tab), or as files included as “Embedded Resources”…
To get the assembly reference to the DLL this is usually the easiest:
In the Resources
If this is part of the default project resources, and not a different .resources file included inside the DLL, you can use the default base-name.
After that you can just call GetObject() and do a cast back:
If you want to find out whats in there, get the assembly reference and call
ass.GetManifestResourceNames()
And this is all assuming they default culture =)
As Embedded Resources
You can use the regular methods on the assembly to get an embedded resource. You find it by name, and then Basically you will need to convert the stream back into your desired type.
I usually use these like this:
To get an image that is an embedded resource, this works for me: