As discussed here, we now discuss StackPanel programatically :
The following program sets the Content property of its window to a StackPanel and then creates 10 buttons that become children of the panel.
StackPanel stack = new StackPanel();
Content = stack;
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Name = ((char)('A' + i)).ToString();
btn.FontSize += rand.Next(10);
btn.Content = "Button " + btn.Name + " says 'Click me'";
btn.Click += ButtonOnClick;
stack.Children.Add(btn);
}
No comments:
Post a Comment