I have a Wpf application project called WpfTest which references WpfTestLib (A class library).
WpfTestLib has a resources file MyResources.resx in a project folder called Resources. MyResources contains a single bmp, bar.bmp. The resource name is bar.
In MyResources.Designer.cs I can see
namespace WpfTestLib.Resources {
and
public class MyResources {
and
public static System.Drawing.Bitmap bar {
I’ve tried to get the image in code by:
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(@"/WpfTestLib;component/Resources/MyResources/bar", UriKind.Relative);
I’ve tried various combinations for the Uri, but no luck. Any ideas? I can get the bar if I add it as an image to the project, with a type of resource. But in this case I want to access it as part of a resource file.
Thanks
Edit: Actually it’s two questions. I have answers to both, but not the bit in the middle that holds it together.
So I can retrieve the image in code using MyResources.bar, which returns a System.Drawing.Bitmap
I can also set the my WPF Image to a resource image using the Uri format shown above. What I can’t do is initialize a WPF Image with a System.Drawing.Bitmap, nor can I find a mapping Uri for a .resx. Hope that helps (you to help me 🙂 )
Ok, I think I’ve found the issue. There’s plenty of information here: That gave me the information I needed to deal with an image properly. Using old style resource dictionaries was then easy peasy.