如何动态定义此按钮?

时间:2011-03-10 22:00:34

标签: c# xaml

如何在C#代码中定义它,以便在运行时创建它?

<Button Canvas.Left="100" Canvas.Top="380" Content="Answer" Height="23" Name="submit_btn" Width="75" Click="submit_btn_Click" />

1 个答案:

答案 0 :(得分:2)

var b = new Button { Text = "Hello World", Left = 100, Top = 100, Width = 50, Height = 25 };
Controls.Add(b);

在InitializeComponent()之后放置在构造函数中。