This is a migrated thread and some comments may be shown as answers.

Image is not getting bind to my grid..

2 Answers 79 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
deepak
Top achievements
Rank 1
deepak asked on 06 Jan 2009, 02:35 PM
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

g.children.add(img1);

Any Suggestions where i went wrong please.......
Thanks a lot
Deepak

2 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 06 Jan 2009, 08:26 PM
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.BeginInit();
firstImg.UriSource = new Uri(firstUri, UriKind.Relative);
firstImg.EndInit();

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

-Serrin
0
chinu
Top achievements
Rank 2
answered on 07 Jan 2009, 11:19 AM
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..
Cheers 
Tags
TabControl
Asked by
deepak
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
chinu
Top achievements
Rank 2
Share this question
or