如何在C#代码中定义它,以便在运行时创建它?
<Button Canvas.Left="100" Canvas.Top="380" Content="Answer" Height="23" Name="submit_btn" Width="75" Click="submit_btn_Click" />
答案 0 :(得分:2)
var b = new Button { Text = "Hello World", Left = 100, Top = 100, Width = 50, Height = 25 };
Controls.Add(b);
在InitializeComponent()之后放置在构造函数中。