How to Add Elements To Canvas From List
-
06 Mei 2012 11:05
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
- Dipindahkan oleh Jeff SandersMicrosoft Employee, Moderator 07 Mei 2012 12:26 Xaml Specific (From:UI Design for Metro style apps)
Semua Balasan
-
07 Mei 2012 15:18Moderator
Please see Canvas.SetLeft and Canvas.SetTop:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.canvas.setleft.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.canvas.settop.aspxMatt Small - Microsoft Escalation Engineer - Forum Moderator If my reply answers your question, please mark this post as answered.
- Disarankan sebagai Jawaban oleh Matt SmallMicrosoft Employee, Moderator 07 Mei 2012 15:18
- Ditandai sebagai Jawaban oleh Bob_BaoMVP, Moderator 07 Juni 2012 9:20