Skip to main content

Microsoft Silverlight

Answered Question Image in silver light 2.0RSS Feed

(0)

anatpk
anatpk

Member

Member

0 points

6 Posts

Image in silver light 2.0

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
chiyau

Member

Member

152 points

16 Posts

Answered Question

Re: Image in silver light 2.0

Hi Anatpk

<Image x:Name = "img_File1"  Source = "imagefilenameAndPath.jpg" />

 The following article may be able to help you understand more about the Image control.

http://www.silverlight-training-guide.com/image-control.html

Cabral
Cabral

Member

Member

64 points

12 Posts

Answered Question

Re: Image in silver light 2.0

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities