布局:
1. <StackPanel Orientation="Vertical">
<TextBlock Text="姓名" FontSize="30" Margin="10,10,10,10"/>
<TextBox Width="150" Height="30"/>
<TextBlock Text="手机" FontSize="30" Margin="10,10,10,10"/>
<TextBox Width="150" Height="30"/>
<TextBlock Text="邮箱" FontSize="30" Margin="10,10,10,10"/>
<TextBox Width="150" Height="30"/>
<TextBlock Text="地址" FontSize="30" Margin="10,10,10,10"/>
<TextBox Width="150" Height="30"/>
</StackPanel>
2.
<Canvas>
<Button Content="按钮1" FontSize="30" Canvas.Left="10" Canvas.Top="10"/>
<Button Content="按钮2" FontSize="30" Canvas.Left="10" Canvas.Top="60"/>
<Button Content="按钮3" FontSize="30" Canvas.Left="10" Canvas.Top="110"/>
<Button Content="按钮4" FontSize="30" Canvas.Left="10" Canvas.Top="160"/>
</Canvas>
3.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="150"/>
<RowDefinition Height="150"/>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<TextBlock Text="姓名" FontSize="30" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="手机" FontSize="30" Grid.Row="1" Grid.Column="0" />
<TextBlock Text="邮箱" FontSize="30" Grid.Row="2" Grid.Column="0"/>
<TextBlock Text="地址" FontSize="30" Grid.Row="3" Grid.Column="0"/>
<TextBox Width="150" Height="30" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Width="150" Height="30" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Width="150" Height="30" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox Width="150" Height="30" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
动态生成:
4.动态生成类:
TextBlock tb = new TextBlock();
tb.Text = "姓名";
tb.FontSize = 30;
Grid.SetRow(tb, 1);
Grid.SetColumn(tb, 0);
grid1.Children.Add(tb);
TextBlock tb1 = new TextBlock();
tb1.Text = "手机";
tb1.FontSize = 30;
Grid.SetRow(tb1, 0);
Grid.SetColumn(tb1, 1);
grid1.Children.Add(tb1);
5.动态生成行和列:
for (int i = 0; i < 10; i++)
{
RowDefinition row = new RowDefinition();
//row.Height = new GridLength(50);
row.Height = GridLength.Auto;
grid1.RowDefinitions.Add(row);
}
for (int i = 0; i < 8; i++)
{
ColumnDefinition col = new ColumnDefinition();
col.Width = GridLength.Auto;
grid1.ColumnDefinitions.Add(col);
}
Random rand = new Random();
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 8; col++)