geeko
geeko

Reputation: 19

Array of buttons WP7

I want to add an array of buttons created in the code of my apps to the UI. It'll be a kind of a grid of buttons. How can i do it in Windows Phone? I tried different ways but i didn't make it. Thanks

Upvotes: 0

Views: 404

Answers (1)

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47068

Create a StackPanel (or Grid or some other panel type that can layout your controls according to your specification).

Create all you buttons (you can put them in a List<Button> to keep track of them) and add each button to StackPanel.Children.

Edit
If you put your Buttons in a Grid and want to put each Button in a separate column you need to set the attached property Grid.Column

Button b = new Button();
grid.Children.Add(b);
b.SetValue(Grid.ColumnProperty, 1); // 1 is column 1, etc.

Upvotes: 1

Related Questions