locked
Making multiple images spawn RRS feed

  • Question

  • I tried googling this but i have no idea how i should word this or what to call it. Basically, i want it so it will show a map of an area and it will check an array if there is anything in that area, if there is itll put a pin at the coordinates. The array bit i can do fine, however in c# i have never figured out how to manually spawn or create an image. in the .Xaml.cs code i am looking for a command that will add the required code () or something similar to the .xaml, i realy dunno how to explain this but i hope you understand what i want. And i do not want to make loads of images in the Xaml and then coordinate their positioning in the .Xaml.CS because i might need more or less then im spawning and so isnt that just pointless?
    Friday, May 14, 2010 7:58 PM

Answers

  •  Just create an Image, set the source, set the coordinates using Canvas.SetLeft and Canvas.SetTop, and add it to a Canvas.

    Friday, May 14, 2010 10:11 PM
  • Skyrunner is correct, but here is more detail. The Uri could be changed to an absolute path if the images are on your server, rather than in your xap (in a folder called Images):

    System.Windows.Controls.Image imageTemp = new System.Windows.Controls.Image();

    imageTemp.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("../Images/page1.jpg", UriKind.Relative));

    imageTemp.SetValue(Canvas.LeftProperty, (double)100);

    imageTemp.SetValue(Canvas.TopProperty, (double)100);

    cvnLayoutRoot.Children.Add(imageTemp);

    Saturday, May 15, 2010 8:15 AM
  • Hi, Headchop...

    I am guessing that your LayoutRoot is a Grid control, for canvas left, right to work, you have to change the layout to Canvas

    <Canvas x:Name="LayoutRoot">

     

    </Canvas>

    Sharker Khaleed Mahmud

    Sunday, May 16, 2010 1:37 AM
  • The images need to be in a canvas. That canvas can be your root control, or it can be nested in the rest of your page. If it is nested, all the left and top references from your images will be relative to that canvas, and not the rest of the page.

    Sunday, May 16, 2010 5:51 AM

All replies

  •  Just create an Image, set the source, set the coordinates using Canvas.SetLeft and Canvas.SetTop, and add it to a Canvas.

    Friday, May 14, 2010 10:11 PM
  • No i dont think you understand me ill try to explain it with a pesudo code:

     In the .Xaml.Cs i want to be able to do something like, in a click event:

     

    int a;

    for (a = 1; a<10; a++)

    {

    Image ImageName = "Pindot" + Convert.ToString(a);

    Image.Make(ImageName);

    ImageName.Top = ..

    ImageName.Left = ..

    ImageName.Texture = ...

    }

     

     

    The code might not be right cos im half asleep but i hope you understand better.

     

    (PS, Opera doesnt keep the formatting of posts :/)

    Thanks in advance

    Saturday, May 15, 2010 7:41 AM
  • Skyrunner is correct, but here is more detail. The Uri could be changed to an absolute path if the images are on your server, rather than in your xap (in a folder called Images):

    System.Windows.Controls.Image imageTemp = new System.Windows.Controls.Image();

    imageTemp.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("../Images/page1.jpg", UriKind.Relative));

    imageTemp.SetValue(Canvas.LeftProperty, (double)100);

    imageTemp.SetValue(Canvas.TopProperty, (double)100);

    cvnLayoutRoot.Children.Add(imageTemp);

    Saturday, May 15, 2010 8:15 AM
  • Thankyou snelldl and so thankyou skyrunner, i got one question though, how do i position it?

                System.Windows.Controls.Image imageTemp = new System.Windows.Controls.Image();
    
                imageTemp.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("../Images/pindot.png", UriKind.Relative));
                
                imageTemp.SetValue(Canvas.LeftProperty, (double)0);
                imageTemp.SetValue(Canvas.TopProperty, (double)0);
                imageTemp.Width = 16;
    
                LayoutRoot.Children.Add(imageTemp);

     i understand that

     

    imageTemp.SetValue(Canvas.LeftProperty, (double)0);

    imageTemp.SetValue(Canvas.TopProperty, (double)0);

    is the code to position it, but whatever i make the numbers its always in the same spot, which is the bottom right hand corner of the form, how do i exactly position the images then?

    and thankyou very much for helping me geting them to appear :)

    Saturday, May 15, 2010 9:03 PM
  • Hi, Headchop...

    I am guessing that your LayoutRoot is a Grid control, for canvas left, right to work, you have to change the layout to Canvas

    <Canvas x:Name="LayoutRoot">

     

    </Canvas>

    Sharker Khaleed Mahmud

    Sunday, May 16, 2010 1:37 AM
  • The images need to be in a canvas. That canvas can be your root control, or it can be nested in the rest of your page. If it is nested, all the left and top references from your images will be relative to that canvas, and not the rest of the page.

    Sunday, May 16, 2010 5:51 AM
  • tyvm all that worked fine
    Sunday, May 16, 2010 5:17 PM