已答复 How to Add Elements To Canvas From List

  • Sonntag, 6. Mai 2012 11:05
     
      Enthält Code

    Hi!

    Sorry, I don't know if it's a basic question or not, i couldn't find anything on the interner.

    I'd like to place positioned items in a grid from a list. This list has items with properies Top and Left. I figured out, i would need a canvas to make my task, but i dont know how to make this from XAML. I tried putting an ItemsControl into the Canvas and bind the Canvas.Top to the Top property, but it didn't work. Then i tried to add my items from code, like this:

    foreach (var item in MyElements) { Image img = new Image(); img.Source = item.MainImage; img.Width = 20; img.Height = 20; img.Stretch = Stretch.UniformToFill; MyCanvas.Children.Add(img); }

    but this way i don't know how to tell the images' position.

    So as a summary, how can i add items to a canvas from a List?

    Thanks,

    Tom

Alle Antworten