Original: WPF notes (1.4 layouts)--hello,wpf!
This section is only the 2nd chapter of the Primer.
Layout to use the Panel control, there are four kinds of panel, as follows:
DockPanel, is to set the docking location layout model.
StackPanel, which provides a stack model for placing content from left to right or from top to bottom.
Grid, which provides a model that allows row/grid positioning. Tables can be used.
Canvas for precise positioning.
The grid is the most commonly used, and the vs2005 automatically generated page and window have this label by default:
Example1- -. A sample usage of the Grid panel
<Window>
<Grid>
<grid.rowdefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</grid.rowdefinitions>
<grid.columndefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</grid.columndefinitions>
<Button Grid.Row="0"Grid.column="0"Grid.columnspan="2">A</Button>
<Button Grid.Row="0"Grid.column="2">C</Button>
<Button Grid.Row="1"Grid.column="0"Grid.rowspan="2">D</Button>
<Button Grid.Row="1"Grid.column="1">E</Button>
<Button Grid.Row="1"Grid.column="2">F</Button>
<Button Grid.Row="2"Grid.column="1">H</Button>
<Button Grid.Row="2"Grid.column="2">I</Button>
</Grid>
</Window>This procedure produces a 3x3 table. Note that you first define the row format, define the column format, and finally put the button into the cell.
Example1- -. Arranging an image and textincha grid
<Button Width=" -"Height=" -">
<button.content>
<Grid>
<grid.rowdefinitions>
<RowDefinition/>
<RowDefinition/>
</grid.rowdefinitions>
<Image Grid.Row="0"Source="Tom.png" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center">Tom</TextBlock>
</Grid>
</button.content>
</Button>This program is added to the picture below a line of caption, is also used under the grid table layout.
The above two examples have grid.row=1 such a grammar--Attached-property the implicated attribute. That is, define () inside the grid and specify the property value in the External control button.
The purpose of the implicated attribute is not necessarily to fill the cell with a button beforehand, so that it is arbitrary for all controls-temporarily, because you don't see Chapter two.
WPF notes (1.4 layouts)--hello,wpf!