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…


