Skip to main content
Home Forums Silverlight Design Designing with Silverlight Image in silver light 2.0
2 replies. Latest Post by Cabral on February 11, 2009.
(0)
anatpk
Member
0 points
6 Posts
02-06-2009 7:25 PM |
Hellow all! It may seem like a dum question, but maybe you can help me. I'm making Silver Light 2.0 Application whit Visual Web Developer Express 2008 SP1. I tried to put an image with the image control. I didn't get any error message but I couldn't see the picture. It's either I used the control in wrong way or I put the picture in a wrong directory or I didn't write the path right. So ... can anybody please show me how to use the image control right, how exactly write the path and where should I put the images directory? Thanks All
chiyau
152 points
16 Posts
02-06-2009 8:07 PM |
Hi Anatpk
<Image x:Name = "img_File1" Source = "imagefilenameAndPath.jpg" />
http://www.silverlight-training-guide.com/image-control.html
Cabral
64 points
12 Posts
02-11-2009 9:48 AM |
I did this method to help in this case.
public static void Source(Image object, string path) { try { //Get the name of the project
string project = ""; project = Application.Current.ToString().Remove(Application.Current.ToString().Length - 4, 4);
//Get the uri including the path of the image string uri = Application.Current.Host.Source.AbsoluteUri.Replace("ClientBin/" + project + ".xap", "") + path; System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); Uri src = new Uri(uri, UriKind.RelativeOrAbsolute);
bmp.UriSource = src;
object.Source = bmp; } catch (Exception ex) { throw ex; } }
when call this method only set the parameter object = imageControl, and path = where the image is.