The layout elements of WPF are as follows:
- Grid: Grid. You can customize rows and columns and adjust the layout of the control by the number of columns, row height, and column width.
- StackPanel: Format panel. You can arrange the elements in the horizontal or vertical direction into a line.
- Canvas: Canvas. Controls placed on the canvas are located with absolute coordinates.
- DockPanel: Parking panel. You can select the direction of the internal element.
- WrapPanel: auto-folding panel. When an internal element is filled with a row, it is automatically folded.
The following mainly records DockPanel, because it is the most difficult to understand during the reading process.
All elements in the DockPanel are appended with the DockPanel. Dock attribute. The data type of this attribute is the Dock enumeration. The Left, Top, Right, and Bottom values can be used in the Dock enumeration. It has a very important property-bool type LastChildFil, which defaults to True. In this case, DockPanel. Dock will fill up the remaining DockPanel controls.
The following is a simple example of a DockPanel:
<Window x:Class="DockPanel.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <DockPanel> <TextBox Text="Top" DockPanel.Dock="Top" Height="25" BorderBrush="Black"/> <TextBox Text="Left" DockPanel.Dock="Left" Width="150" BorderBrush="Black"/> <TextBox Text=" LastChild" BorderBrush="red"/> </DockPanel> </Grid></Window>