Coffeehouse Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Working with the Image Control - Day 3 - Part 1 - Bob Tabor Tutorial

Back to Forum: Coffeehouse
  • User profile image
    Phil_Kearney

    Hi I recently started working through Bob's tutorials. Got them all working fine, although I can't seem to get the image to load when I click Load. I have the image in the correct folder. 

        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
    
                BitmapImage myImage = new BitmapImage(new Uri("/Images;component/Images/Penguins.jpg", UriKind.Relative));
                image1.Source = myImage;
    
            }
        }
    }

    That is my code, Identical to what Bob has in his video, well I think it is anyhow. Any ideas?

     

    Thanks Phil.

  • User profile image
    vesuvius

    Be sure to right click the image, go to properties and ensure its build action is set to resource. That is usually the problem with loading images. Also I would (terseness);

           image1.Source =  new BitmapImage(new Uri("/Images;component/Images/Penguins.jpg", UriKind.Relative));    

  • User profile image
    cbae

    @Phil_Kearney: Are you sure that that's a valid URI? ("/Images;component/Images/Penguins.jpg")

     

  • User profile image
    vesuvius

    @cbae: Now that you mention it the /Images;component/ part look wrong, the Images part should be the namespace of the assembly and not the name of the folder

  • User profile image
    Harlequin

    If you have Blend, drag the image onto a surface. Then you can just copy the Url that is in the Xaml, it will have the right path to the image. And yeah, always double check the build action.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.