Image is not getting bind to my grid..

3 posts, 0 answers
  1. deepak
    deepak avatar
    3 posts
    Member since:
    Dec 2008

    Posted 06 Jan 2009 Link to this post

    Hi ..
    Now I am stuck into another problem(but i hope its very simple..)  

    Actually i am not able to load my image when i run my application.. it seems its a pity error.. but still.. code seems to be all right to me

      BitmapImage firstImg = new BitmapImage();

     string path = "../_assets/Themes/0/icons/51-icon.png";

     firstImg.UriSource = new Uri(firstUri, UriKind.Relative);

    Image img1;

      img1 = new Image()
                    Source = firstImg,
                    Width = 50,
                    Height = 50,
                    Cursor = Cursors.Hand,
                    VerticalAlignment = VerticalAlignment.Top,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Visibility = Visibility.Visible

    Then i have defined a grid and tried to add this image to my grid but its not running and an internal exception "Invalid Operation exception" is coming


    Any Suggestions where i went wrong please.......
    Thanks a lot
  2. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 06 Jan 2009 Link to this post

    Hi Deepak,

    You missed one little thing (well two, to be specific) that I only just learned about today because I was trying to do something similar.  Where you have...

    firstImg.UriSource = new Uri(firstUri, UriKind.Relative);

    You need to wrap it in a Begin and End tag, like this:

    firstImg.UriSource = new Uri(firstUri, UriKind.Relative);

    This is a requirement for the BitmapImage class as mentioned here.

  3. DevCraft R3 2016 release webinar banner
  4. chinu
    chinu avatar
    3 posts
    Member since:
    Jan 2009

    Posted 07 Jan 2009 Link to this post

    Hi Serrin ,
    Thanks for telling me that..but actually the problem was in my mapping to the folder in which image was located..But i will also make it a habit to do those two things as well..
Back to Top