收藏:MSDN中关于WPF元素定位的范例代码

收藏:MSDN中关于WPF的HorizontalAlignment、Margin、Padding 和 VerticalAlignment 的范例代码


  1. <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Margins, Padding and Alignment Sample">
  2. <Border Background="LightBlue"
  3. BorderBrush="Black"
  4. BorderThickness="2"
  5. CornerRadius="45"
  6. Padding="25">
  7. <Grid Background="White" ShowGridLines="True">
  8. <Grid.ColumnDefinitions>
  9. <ColumnDefinition Width="Auto"/>
  10. <ColumnDefinition Width="*"/>
  11. <ColumnDefinition Width="Auto"/>
  12. </Grid.ColumnDefinitions>
  13. <StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Name="StackPanel1" VerticalAlignment="Top">
  14. <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel1</TextBlock>
  15. <Button Margin="0,10,0,10">Button 1</Button>
  16. <Button Margin="0,10,0,10">Button 2</Button>
  17. <Button Margin="0,10,0,10">Button 3</Button>
  18. <TextBlock>ColumnDefinition.Width="Auto"</TextBlock>
  19. <TextBlock>StackPanel.HorizontalAlignment="Left"</TextBlock>
  20. <TextBlock>StackPanel.VerticalAlignment="Top"</TextBlock>
  21. <TextBlock>StackPanel.Orientation="Vertical"</TextBlock>
  22. <TextBlock>Button.Margin="0,10,0,10"</TextBlock>
  23. </StackPanel>
  24. <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" Name="StackPanel2" VerticalAlignment="Top" Orientation="Vertical">
  25. <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel2</TextBlock>
  26. <Button Margin="10,0,10,0">Button 4</Button>
  27. <Button Margin="10,0,10,0">Button 5</Button>
  28. <Button Margin="10,0,10,0">Button 6</Button>
  29. <TextBlock HorizontalAlignment="Center">ColumnDefinition.Width="*"</TextBlock>
  30. <TextBlock HorizontalAlignment="Center">StackPanel.HorizontalAlignment="Stretch"</TextBlock>
  31. <TextBlock HorizontalAlignment="Center">StackPanel.VerticalAlignment="Top"</TextBlock>
  32. <TextBlock HorizontalAlignment="Center">StackPanel.Orientation="Horizontal"</TextBlock>
  33. <TextBlock HorizontalAlignment="Center">Button.Margin="10,0,10,0"</TextBlock>
  34. </StackPanel>
  35. <StackPanel Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" Name="StackPanel3" VerticalAlignment="Top">
  36. <TextBlock FontSize="18" HorizontalAlignment="Center" Margin="0,0,0,15">StackPanel3</TextBlock>
  37. <Button Margin="10">Button 7</Button>
  38. <Button Margin="10">Button 8</Button>
  39. <Button Margin="10">Button 9</Button>
  40. <TextBlock>ColumnDefinition.Width="Auto"</TextBlock>
  41. <TextBlock>StackPanel.HorizontalAlignment="Left"</TextBlock>
  42. <TextBlock>StackPanel.VerticalAlignment="Top"</TextBlock>
  43. <TextBlock>StackPanel.Orientation="Vertical"</TextBlock>
  44. <TextBlock>Button.Margin="10"</TextBlock>
  45. </StackPanel>
  46. </Grid>
  47. </Border>
  48. </Page>
posted @ 2010-10-29 11:09  Lester Duo  Views(2895)  Comments(0Edit  收藏  举报