Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand WPF layout and layout container

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report