//具現化一個Grid
Grid grid = new Grid();
//設置RowDefinition
RowDefinition row1 = new RowDefinition();
row1.Height = new GridLength(20);
grid.RowDefinitions.Add(row1);
RowDefinition row2 = new RowDefinition();
row2.Height = new GridLength(80);
grid.RowDefinitions.Add(row2);

 

Button b = new Button();
b.Height = 20;
b.Width = 30;
b.HorizontalAlignment = HorizontalAlignment.Right;
b.Content = "關閉";
b.Click += b_Click;
//將Button添加到Grid中
grid.Children.Add(b);
//設置Button在Grid中的位置
b.SetValue(Grid.RowProperty, 0);

 

TextBlock txt = new TextBlock();
txt.Text = "this is a test";
txt.Height = 80;
txt.Width = 200;
//將TextBlock添加到Grid中
grid.Children.Add(txt);
//設置TextBlock在Grid中的位置
txt.SetValue(Grid.RowProperty, 1);
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()