收藏:MSDN中关于WPF元素定位的范例代码
收藏:MSDN中关于WPF的HorizontalAlignment、Margin、Padding 和 VerticalAlignment 的范例代码
- <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Margins, Padding and Alignment Sample">
- <Border Background="LightBlue"
- BorderBrush="Black"
- BorderThickness="2"
- CornerRadius="45"
- Padding="25">
- <Grid Background="White" ShowGridLines="True">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto"/>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Name="StackPanel1" VerticalAlignment="Top">
- <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel1</TextBlock>
- <Button Margin="0,10,0,10">Button 1</Button>
- <Button Margin="0,10,0,10">Button 2</Button>
- <Button Margin="0,10,0,10">Button 3</Button>
- <TextBlock>ColumnDefinition.Width="Auto"</TextBlock>
- <TextBlock>StackPanel.HorizontalAlignment="Left"</TextBlock>
- <TextBlock>StackPanel.VerticalAlignment="Top"</TextBlock>
- <TextBlock>StackPanel.Orientation="Vertical"</TextBlock>
- <TextBlock>Button.Margin="0,10,0,10"</TextBlock>
- </StackPanel>
- <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" Name="StackPanel2" VerticalAlignment="Top" Orientation="Vertical">
- <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel2</TextBlock>
- <Button Margin="10,0,10,0">Button 4</Button>
- <Button Margin="10,0,10,0">Button 5</Button>
- <Button Margin="10,0,10,0">Button 6</Button>
- <TextBlock HorizontalAlignment="Center">ColumnDefinition.Width="*"</TextBlock>
- <TextBlock HorizontalAlignment="Center">StackPanel.HorizontalAlignment="Stretch"</TextBlock>
- <TextBlock HorizontalAlignment="Center">StackPanel.VerticalAlignment="Top"</TextBlock>
- <TextBlock HorizontalAlignment="Center">StackPanel.Orientation="Horizontal"</TextBlock>
- <TextBlock HorizontalAlignment="Center">Button.Margin="10,0,10,0"</TextBlock>
- </StackPanel>
- <StackPanel Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" Name="StackPanel3" VerticalAlignment="Top">
- <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel3</TextBlock>
- <Button Margin="10">Button 7</Button>
- <Button Margin="10">Button 8</Button>
- <Button Margin="10">Button 9</Button>
- <TextBlock>ColumnDefinition.Width="Auto"</TextBlock>
- <TextBlock>StackPanel.HorizontalAlignment="Left"</TextBlock>
- <TextBlock>StackPanel.VerticalAlignment="Top"</TextBlock>
- <TextBlock>StackPanel.Orientation="Vertical"</TextBlock>
- <TextBlock>Button.Margin="10"</TextBlock>
- </StackPanel>
- </Grid>
- </Border>
- </Page>