水平对齐:

<Gridx:Name="ContentPanel"Grid.Row="1"Margin="12,0,12,0"><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><ButtonContent="Left左部对齐"Height="80"Width="220"HorizontalAlignment="Left"></Button><ButtonGrid.Row="1"Content="Right右部对齐"Width="220"Height="80"HorizontalAlignment="Right"></Button><ButtonGrid.Row="2"Width="220"Height="80"Content="Center剧中对齐"HorizontalAlignment="Center"></Button><ButtonGrid.Row="30"Height="80"HorizontalAlignment="Stretch"Content="Stretch拉伸对齐"></Button></Grid>

注意:Stretch:元素以垂直填充的方式进行布局

HorizontalAlignment要使用Stretch值,就不能设置元素的Width属性,否则Stretch值将不会起作用。

垂直对齐:

<Gridx:Name="ContentPanel"Grid.Row="1"Margin="12,0,12,0"><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><ButtonContent="Top顶端对其"Height="80"Width="220"VerticalAlignment="Top"></Button><ButtonGrid.Row="1"Content="Center居中对齐"Width="220"Height="80"VerticalAlignment="Center"></Button><ButtonGrid.Row="2"Width="220"Height="80"Content="Bottom底部对齐"VerticalAlignment="Bottom"></Button><ButtonGrid.Row="30"Width="220"VerticalAlignment="Stretch"Content="Stretch拉伸对齐"></Button></Grid>

注意:Stretch:元素以水平方向填充父元素的布局空间

VerticalAlignment在使用Stretch值时,就不能设置元素的Height属性,否则Stretch将不会起作用。