Home > Back-end >  How to find the position of an Image in WPF C#?
How to find the position of an Image in WPF C#?

Time:06-15

I have an array which stores many images within in. I am trying to figure out how to get the position of the image (x,y) within the window. I aim to put it in a timer so I can get the updated location as the program runs.

The images are added with the following code:

arrayName[p] = new Image();
arrayName[p].Source = new BitmapImage(new Uri(@"imgPlaneSprite.png", UriKind.Relative));
arrayName[p].Width = 50;
arrayName[p].Height = 50;
arrayName[p].Stretch = Stretch.Fill;

LayoutRoot.Children.Add(arrayName[p]);

CodePudding user response:

try this:

arrayName[p].PointToScreen(new Point(0, 0));
  • Related