Loading an image from inside a WPF dll from control code
This was a mail thread that I was on…wanted to publish for searchability in the future.
Read bottom to top:
Correct syntax to use is:
img.UriSource = new Uri("pack://application:,,,/FunControlsBagLibrary;component/PresenceControl/Images/online.png", UriKind.Absolute);
I’m currently working on a little Control ToolKit for WPF which will have different controls in it. So I’ve developed a library in which I’ve putted all the classes for each of my controls.
But for one of my class/control, I need to load/display images so I would like to embed these image within the library and display them when I want but I don’t know the correct syntax to use because this give me an exception (“Cannot locate resource ‘images/online.png’.”):
img.UriSource = new Uri(@"pack://application:,,,/Images/online.png");
First, is it the correct way to do this (embedded images and loading them from the resources) ? If yes, which syntax do I need to use ?