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


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="" />

so how can we define this source from code file.

string imgurl = " ";

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("", Urikind.Absolute);

ImageSource imgs = new ImageSource(uri);

imgPhoto.Source = imgs;

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



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 )

Google+ photo

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

%d bloggers like this: