Adding UI Components in C# WPF in Code behind -


I'm new in C # and WPF format. In my program, I have an array of strings with text, and I want to create a button in the array for each string in the canvas. I have used Flex, and I can use the addChild command to put something in something else, but I do not know how to do it in WPF now thanks any help would be appreciated, thanks.

I hope it can start you (untested!):

  foreach (var s) in the text array {button b = new button (); // Set button width / height / text ... myCanvas.AddChild (b); // Status button on Canvas (Set Attached Properties) Canvas SetLeft (b, ...); // Fill in the ellips canvas.Settop (B, ...); }  

A more advanced technique will allow you to synchronize the UI in the content of your array.

I highly recommend the book "WPF Unleashed" to learn WPF


Comments