Setting source of Images

This week end, I am so busy with my heavy work load… homework! But, I still want to share my experience on writeing Silverlight Application.

As I remembered, I have seen more than ten posts asking for the blinding of the source of their images.

Actually people want to make use of the images that they added to the project.

Honestly speaking, it has so many ways to do the trick.

First one:

Image Img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("pic.gif", UriKind.Relative);
Img.Source = bi3;

Let me explain a little bit. If you added the image to your project, it is better for you to use UriKind.Relative. Just like the word “Relative” it is taking the resources relatively to the project. But how about somethings that are not added to the project?

Image Img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("http://localhost/pic.gif", UriKind.Absolute);
Img.Source = bi3;

Apart from setting it programmatically with C#, you can also add it with xaml code throught C#.

Image img = XamlReader.Load(" " ) as Image;

It is rare to see people using XamlReader, but it can really do the trick!

Live with Light
Steve Wong (Hong Kong)

One thought on “Setting source of Images

  1. Finally, replace the bag and clean or replace
    the now dirty exhaust filter. And while they are extremely efficient machines
    that clean large areas in record time, they are also easy to operate for that spilled ashtray or other
    debris that needs to be picked up quickly. Takeaway
    containers may warp or melt, also releasing toxic chemicals
    into the food.


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s