Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand WPF layout and layout container

Shulou Source: shulou.com Published: 2022-06-01 21:25:40 10月22日 Update

This article shows you how to understand the WPF layout and layout container, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

WPF layout basic WPF layout principles

Only one element can be contained in a window

Setting element size should not be displayed

You should not use coordinates to set the location of an element

Layout containers can be nested

WPF layout container

StackPanel: arrange elements horizontally or vertically, and Orientation attributes: Horizontal / Vertical

WrapPanel: arranges elements horizontally or vertically, wrapping lines or columns for insufficient remaining space

DockPanel: Dock.Top, Left, Right, Bottom settings based on container boundaries and elements

Grid: similar to table table, flexible to set rows and columns and place control elements, more commonly used

UniformGrid: specify the number of rows and columns, sharing limited container space equally

Canvas: use fixed coordinates to set the location of the element, do not have anchor docking and other functions.

Layout Container detailed StackPanel

StackPanel is mainly used to arrange elements vertically or horizontally, and to place a limited number of elements within the available dimensions of the container. The sum of the elements (length / height) is not allowed to exceed the size of the StackPanel, otherwise the excess is not visible.

WrapPanel

The default orientation of WrapPanel is opposite to that of StackPanel, and the origin of WrapPanel defaults to Horizontal.

WrapPanel has the function of StackPanel and can automatically wrap lines to adapt to the width and height of the container after the size change.

DockPanel

The element in the default DockPanel has a DockPanel.Dock attribute, which is an enumeration with: Top, Left, Right, Bottom.

By default, DockPanel.Dock attributes are not added to elements in DockPanel, and Left is added by default.

DockPanel has a LastChildFill attribute, which defaults to true, which acts to fill all DockPanel spaces by default when the last element in the container is filled.

Grid

Brothers who have studied web should know table tables, and Grid is similar to Grid, which has the ability to divide space.

RowDefinitions / ColumnDefinitions is used to assign rows and columns to Grid.

ColumnSpan / RowSpan is used to set the cross-column and wide rows of spatial elements.

Canvas

The container is equivalent to a "map", containing all the control elements, are located by using XY, because it is not very common, so it is simply skimmed.

The above is how to understand WPF layout and layout containers. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Elements containers layouts attributes dimensions spaces levels locations contents functions coordinates foundations skills controls limitations knowledge tables conciseness conciseness function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Huawei Redmi Shulou Tech Info