[问题] WPF动态新增buttons

楼主: bravehuang (Brave-man)   2017-08-12 00:49:02
WPF新手请问如何跟Winform一样能从*.cs的程式码中动态新增Button?
还是只能透过XAML新增button物件? 无法透过*.cs新增?
谢谢
===
在*.cs中新增5x5个button
int x0 = 100, y0 = 10, w = 45, h = 50;
int row = 0, column = 0;
int N = 5;
for(row = 0; row < N; row++)
{
for(column = 0; column < N; column++)
{
int num = row * N + column;
Button btn = new Button();
btn.Content = (num + 1).ToString();
btn.Width = w;
btn.Height = h;
btn.Margin = new Thickness(x0 + w * column, y0 + h * row, 0, 0);
btn.IsEnabled = true;
}
}
作者: testPtt (测试)   2017-08-12 07:14:00
没设定要放在哪

Links booklink

Contact Us: admin [ a t ] ucptt.com