温馨提示×

如何动态添加元素到StackPanel

小樊
81
2024-07-02 20:54:10
栏目: 编程语言

要向StackPanel动态添加元素,可以使用Children属性中的Add方法。例如:

StackPanel stackPanel = new StackPanel();

Button button = new Button();
button.Content = "Click me";
stackPanel.Children.Add(button);

这将在StackPanel中添加一个新的Button元素。您可以在需要时创建和添加任何元素,如Button、TextBlock等。

0