<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<!--Window的属性以及命名空间引用信息-->
<Grid>
<!--Grid行列布局控件(默认占满所有空间),里面可以放多个控件,如果没有则Window只能存在一个Content,这是客户区的操作,非客户区时标题最小化最大化等区域-->
<!--StackPanel是行列自动布局,将子元素按照堆栈的形式-->
<!--分行,先写行定义标签,然后分行-->
<!--1*按比例分(原理:每个占1/(1+1+1+1),如果填其他数字*则一样按照这个公式),也可以直接填写高度数值-->
<!--Auto根据内容分-->
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!--将按钮分配到第0行,第0列-->
<!--Grid.Column:指定列位置,Grid.Row:指定行位置,HorizontalAlignment:指定垂直对齐,VerticalAlignment:指定平行对齐,Margin:边距-->
<Button Content="aa" Grid.Column="0" Grid.Row="0" Width="30" HorizontalAlignment="Left" Margin="50,0,0,0"/>
<Button Content="aa" Grid.Column="0" Grid.Row="0" Width="30" HorizontalAlignment="Left" Margin="100,0,0,0"/>
<!--我们还可以在Grid里面嵌套StackPanel,Orientation可以设置横竖排列控件,但会默认居中-->
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
<Button Height="20" Width="150" Content="StackPanel里的Button"/>
<Button Height="20" Width="150"/>
</StackPanel>
<!--我们还可以在Grid里面嵌套Grid,放到第三行-->
<Grid Grid.Row="2" Grid.Column="0" Background="Azure">
<Button Height="20" Width="160" Content="Grid嵌套的Button"/>
</Grid>
<!--分列,先写列定义标签,然后分列-->
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
</Window>