The layout of WPF consists of six panels: stackpanel, wrappanel, dockpanel, canvas, and grid) and uniformgrid ). The following describes the features of several panels:
1. stackpanel
Stack panel, which can arrange elements into one row or one column. Each element occupies one row or one column. Orientation attribute specifies the arrangement method: vertical (vertical) [Default], horizontal (horizontal ). By default, in horizontal arrangement, each element is as high as the Panel; in vertical arrangement, each element is as wide as the panel.
2. wrappanel
Wrap the Panel. When the element layout reaches the boundary, it can wrap automatically. The usage is the same as that of stackpanel.
3. dockpanel
To dock a panel, you can specify one side of the Panel to each element. When the Panel size changes, the button will be docked Based on the specified side. In the dockpanel, the control that specifies the dock edge occupies the corner according to the defined order, and all the controls will never overlap. By default, only the remaining space can be used for the added elements. The last element fills in all the remaining space. If you do not want the last element to fill the remaining area, you can set the dockpanel attribute lastchildfill to false.
4. Canvas
Canvas, used to completely control the exact position of each element. It is the simplest layout control. It directly places elements in a specified position and mainly arranges pictures. When using canvas, you must specify the position of a word element (relative to the canvas). Otherwise, all elements will appear in the upper left corner of the canvas. Adjust the position with four additional attributes: Left, right, top, and bottom. If the canvas is the main element of the window, the canvas will change when the window size is changed, and the position of the word element will also move to ensure that the location attribute relative to the canvas remains unchanged. The canvas allows some or all of the child elements to exceed its boundary. By default, the child elements are not clipped, and negative coordinates can be used. Therefore, the size of the canvas is not required. To copy the canvas content, set cliptobounds to true.
5. Grid
The grid panel layout elements in the form of tables. The layout of elements on the entire panel effectively solves the consistency between multiple rows and between multiple columns. A grid is similar to a table on a webpage. It defines a grid. rows and columns are defined and cells are divided. The coordinates start from (0, 0. The column width and row height can be specified in columndefinition and rowdefinition respectively. First, define the grid, then define the element, and specify the cell where the element is located. If no cell is defined, the elements are placed in the first cell () by default ).
6. uniformgrid
Uniform layout grid. As the name suggests, all cells are evenly arranged and the size is the same. You can specify the number of rows and columns for them. The uniformgrid splits the canvas by row and column, and each control has a cell.