-2

I have a List of objects and i want to create a Foreach loop which create images on my MainWindow separated by 50 pixels for example. I don't know if I have to create them in the desgner itself or if there's a way to create then place the images the one below the other in a command. For example i have:

List<string> URIS = new List<string>();

foreach (var i in URIS) 
{
    //New image in MainWindow with source i
}

Remember that I want a "list" of images in my Window so that every image is below the last one.

Yooooomi
  • 895
  • 1
  • 8
  • 20
  • Create them, set their position, and add them to the form's `Controls` collection. – D Stanley Jun 29 '16 at 19:43
  • Take a look at ItemsControl. Set (or bind) its ItemsSource property to your URI list. Put an Image control in its ItemTemplate and set the Image's Source property like ``. – Clemens Jun 29 '16 at 19:44
  • Seems like you are talking chinese to me :/ – Yooooomi Jun 29 '16 at 19:48
  • Check out this post. http://stackoverflow.com/questions/347614/wpf-image-resources – Nick Acosta Jun 29 '16 at 19:54
  • @Ay0m3 If that sounds chinese, start reading here: [Data Templating Overview](https://msdn.microsoft.com/en-us/library/ms742521(v=vs.100).aspx). There's also plenty of Q&A here on StackOverflow about the topic, e.g. this: http://stackoverflow.com/a/34557467/1136211 – Clemens Jun 29 '16 at 20:11

1 Answers1

1

Look into the ItemsControl. It has an ItemsSource property that takes a list and lays out its items into a visual list. You can use the ItemTemplate property to control exactly what type of visual is created from each list item, including things like spacing.

tsandy
  • 911
  • 4
  • 10