1. 布局结果如下

C# WPF UI Tutorials之一——布局 - 图1

2. XAML代码

  1. <Window x:Class="项目10.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:sys="clr-namespace:System;assembly=mscorlib"
  7. xmlns:local="clr-namespace:项目10"
  8. mc:Ignorable="d"
  9. Title="MainWindow" Width="500" Height="850" MinWidth="300" MinHeight="500" WindowStartupLocation="CenterScreen">
  10. <Border Padding="15">
  11. <StackPanel>
  12. <!-- Button -->
  13. <Grid>
  14. <Grid.ColumnDefinitions>
  15. <ColumnDefinition Width="*"></ColumnDefinition>
  16. <ColumnDefinition Width="*"></ColumnDefinition>
  17. <ColumnDefinition Width="*"></ColumnDefinition>
  18. </Grid.ColumnDefinitions>
  19. <Button Grid.Column="0" x:Name="ButtonApply" Margin="0 0 10 0">Apply</Button>
  20. <Button Grid.Column="1" x:Name="ButtonReset" Margin="3 0 3 0">Reset</Button>
  21. <Button Grid.Column="2" x:Name="ButtonRefresh" Margin="10 0 10 0">Refresh</Button>
  22. </Grid>
  23. <!-- Description -->
  24. <TextBlock Margin="0 10" FontWeight="Bold">Pluse Properties</TextBlock>
  25. <TextBlock>Description</TextBlock>
  26. <TextBox Padding="2"></TextBox>
  27. <Grid>
  28. <Grid.ColumnDefinitions>
  29. <ColumnDefinition Width="2*"></ColumnDefinition>
  30. <ColumnDefinition Width="*"></ColumnDefinition>
  31. </Grid.ColumnDefinitions>
  32. <!--Stauts-->
  33. <StackPanel Grid.Column="0" Margin="0 0 10 0" Orientation="Vertical">
  34. <TextBlock>Status</TextBlock>
  35. <TextBox IsReadOnly="True" Padding="2" Background="#eee"></TextBox>
  36. </StackPanel>
  37. <StackPanel Grid.Column="1" Orientation="Vertical">
  38. <TextBlock>Revision</TextBlock>
  39. <TextBox IsReadOnly="True" Padding="2" Background="#eee"></TextBox>
  40. </StackPanel>
  41. </Grid>
  42. <TextBlock>Part Number</TextBlock>
  43. <TextBox IsReadOnly="True" Padding="2" Background="#eee"></TextBox>
  44. <TextBlock Margin="0 10" FontWeight="Bold">Raw Material</TextBlock>
  45. <TextBlock>Material</TextBlock>
  46. <ComboBox Padding="2"></ComboBox>
  47. <TextBlock Margin="0 10" FontWeight="Bold">Manufacturing informations</TextBlock>
  48. <TextBlock>Work Centers</TextBlock>
  49. <Grid Margin="2">
  50. <Grid.ColumnDefinitions>
  51. <ColumnDefinition Width="*"></ColumnDefinition>
  52. <ColumnDefinition Width="*"></ColumnDefinition>
  53. </Grid.ColumnDefinitions>
  54. <StackPanel Grid.Column="0" Margin="0,0,10,0" Orientation="Vertical">
  55. <CheckBox Margin="1">Weld</CheckBox>
  56. <CheckBox Margin="1">Assembly</CheckBox>
  57. <CheckBox Margin="1">Plasma</CheckBox>
  58. <CheckBox Margin="1">Laser</CheckBox>
  59. <CheckBox Margin="1">Purchase</CheckBox>
  60. </StackPanel>
  61. <StackPanel Grid.Column="1" Orientation="Vertical">
  62. <CheckBox Margin="1">Lathe</CheckBox>
  63. <CheckBox Margin="1">Drill</CheckBox>
  64. <CheckBox Margin="1">Fold</CheckBox>
  65. <CheckBox Margin="1">Roll</CheckBox>
  66. <CheckBox Margin="1">Saw</CheckBox>
  67. </StackPanel>
  68. </Grid>
  69. <TextBlock Margin="0,3">Lenth</TextBlock>
  70. <TextBox Padding="3"></TextBox>
  71. <TextBlock Margin="0,3">Mass</TextBlock>
  72. <TextBox IsReadOnly="True" Padding="2" Background="#eee"></TextBox>
  73. <TextBlock Margin="0,3">Finish</TextBlock>
  74. <ComboBox Padding="2" SelectedIndex="0">
  75. <ComboBoxItem>Painted</ComboBoxItem>
  76. <ComboBoxItem>UnPainted</ComboBoxItem>
  77. </ComboBox>
  78. <TextBlock Margin="0,3">Purchase information</TextBlock>
  79. <ComboBox Padding="2" SelectedIndex="0">
  80. <ComboBoxItem>Rubber</ComboBoxItem>
  81. <ComboBoxItem>UnRubber</ComboBoxItem>
  82. </ComboBox>
  83. <TextBlock Margin="0,3">Supplier Name</TextBlock>
  84. <TextBox Padding="2"></TextBox>
  85. <TextBlock Margin="0,3">Supplier Code</TextBlock>
  86. <TextBox Padding="2"></TextBox>
  87. <TextBlock Margin="0 10" FontWeight="Bold">Additional information</TextBlock>
  88. <TextBlock>Note</TextBlock>
  89. <TextBox Padding="2"></TextBox>
  90. </StackPanel>
  91. </Border>
  92. </Window>