Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Set Source on Image from code in Silverlight

Posted by Viral Sarvaiya on January 11, 2011

Hi

this is the first post of year 2o11

here I demonstrate how to set source of the image from code in silverlight

basically we define source of image from XAML file as below


<Image x:name="imgPhoto" Source="http://www.viralsarvaiya.wordpress.com/imgphoto.jpg" />

so how can we define this source from code file.


string imgurl = " http://www.viralsarvaiya.wordpress.com/imgphoto.jpg ";

ImageSourceConvertor convertor = new ImageSourceConvertor();

imgPhoto.Source = (ImageSource) convertor.ConvertFromString(imgurl);

here we use ImageSourceConvertor but u can also use BitmapImage with an Uri class as below,


Uri uri = new Uri("http://www.viralsarvaiya.wordpress.com/imgphoto.jpg", Urikind.Absolute);

ImageSource imgs = new ImageSource(uri);

imgPhoto.Source = imgs;

with this you can define source of the image from source.

Enjoy…

Advertisements

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: