myPanel.Controls.Add(按钮);不起作用
myPanel.Controls.Add(button); doesn´t work
我在 test.Xaml
视图和 test.xaml.cs
文件中创建了一个 StackPanel
我想以编程方式添加一个按钮:
//function: add buttons
private void add_Buttons()
{
Button myButton = new Button();
myStackPanel.Controls.Add(myButton);
}
Controls
这个词有红色下划线,错误告诉我:
myStackPanel doesn´t have a Definition or Method of Controls
我认为 "Controls" 方法一直存在,还是我必须将其添加到 xaml 查看器或其他地方?
在像 StackPanel
这样的 WPF 容器控件中有 Children
属性 而不是 Controls
:
Button myButton = new Button();
myStackPanel.Children.Add(myButton);
我在 test.Xaml
视图和 test.xaml.cs
文件中创建了一个 StackPanel
我想以编程方式添加一个按钮:
//function: add buttons
private void add_Buttons()
{
Button myButton = new Button();
myStackPanel.Controls.Add(myButton);
}
Controls
这个词有红色下划线,错误告诉我:
myStackPanel doesn´t have a Definition or Method of Controls
我认为 "Controls" 方法一直存在,还是我必须将其添加到 xaml 查看器或其他地方?
在像 StackPanel
这样的 WPF 容器控件中有 Children
属性 而不是 Controls
:
Button myButton = new Button();
myStackPanel.Children.Add(myButton);