Skip to content

Loading an image from inside a WPF dll from control code

February 5, 2007

 

This was a mail thread that I was on…wanted to publish for searchability in the future.

Read bottom to top:

———

Answer:
Correct syntax to use is:

img.UriSource = new Uri("pack://application:,,,/FunControlsBagLibrary;component/PresenceControl/Images/online.png", UriKind.Absolute);

—-

Question:

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 ?

From → WPF

One Comment
  1. Vinayaka permalink

    Hey, Thank you. So much, it was a perfect solution I was looking for. Thanks AGAIN !!!!!!!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: