1

I am adding an unknown amount of images to a canvas at runtime via code behind but I suspect they are laying on top of each other so only 1 image is visible.

I am converting multiple page PDF's into jpg images with ghostscript and wish to add them to a canvas in a vertical sequential row inside a scroll viewer.

Currently I am just rolling through a for loop generating each jpg and adding it to the canvas with canvas.children.add()

Is there a common way to ensure elements added to a canvas do not overlap? Or a common method people use to make sure children.add places the element in the right position?

I am thinking inside my for loop I will need to see what else exists on the canvas and add the heights together and palace my new image at the correct position but I am not sure how this is done. Is anyone able to steer me in the right direction?

Rand Random
  • 7,300
  • 10
  • 40
  • 88
RedChair
  • 43
  • 7
  • Sorry, I tried to add code in my question but I couldn't get the 'add code here' thing to recognize my code so half was in a code box and half wasn't and it looked very untidy – RedChair Feb 05 '18 at 15:23

1 Answers1

2

You could use a StackPanel instead of the Canvas and add the images in there. The StackPanel will then place the images next to each other (or one under another, depending on its Orientation).

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
  • Perfect! Thank you. I have a few issues to iron out after changing type to stackpanel but I am on my way again. Thanks ChrFin. :) – RedChair Feb 05 '18 at 22:53