[問題] 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