Compartilhar via


O WPF recipiente controles Visão geral

Container controls such as Grid, Canvas, or StackPanel, allow you to rapidly design varied and functional user interfaces by providing built-in layout functionality. Each container control handles the layout and positioning of its contained controls, and can provide properties to contained controls that assist with positioning. This topic provides an overview of the different types of container controls and how they affect the layout of their contained controls.

Arredondamento de layout

Definir o controle de contêiner UseLayoutRoundingdepropriedade para especificar quando a pixel integral não-valores que são calculados durante a Measure e Arrange passagens são arredondadas para valores de pixel inteiro. Esta propriedade é herdada por controles filho .

Grid

The most familiar container control is the Grid control. Por padrão, cada nova Window aberto no WPF Designer for Visual Studio inclui um Grid de controle. The Grid allows you to position controls within user-definable cells. Controls placed in cells maintain a fixed margin between two or more control edges and cell edges when the Window is resized. For more information about how to set the margins, see Como: Definir margens para um controle no criador de WPF.

When added to a Window, a Grid control consists of a single cell. Additional vertical and horizontal rows can be added in code or in the WPF Designer. For more information, see Como: adicionar linhas e colunas para uma grade.

UniformGrid

The UniformGrid control provides a simplified grid layout for controls. As controls are added to the UniformGrid, they are laid out in a grid pattern that is automatically adjusted to keep an even distance between the controls. The number of cells is adjusted to accommodate the number of controls. For example, if four controls are added to a UniformGrid, they will be arranged in a grid with four cells.

Canvas

O Canvas controle suporta o posicionamento absoluto e fornece a-menos construído na funcionalidade de layout para seus controles contidos. Canvaspermite que você os controles de posição contido em um deslocamento de qualquer canto do painel. Canvasfornece quatro propriedades para controles contidos: Top, Bottom, Right, and Left. Controls contained in a Canvas control must specify one horizontal property and one vertical property, thereby designating the corner that the control will be offset from. For example, if a control specifies values for Top and Right, it will maintain a constant distance from the upper right-hand corner. If values for more than one horizontal or vertical property are specified, then one of the values will be ignored. For more information, see Como: Criar um layout com base no posicionamento absoluto.

StackPanel

StackPanel arranges contained controls in either a vertical stack or in a horizontal row, depending on the value of the Orientation property. If more controls are added to a StackPanel than can be displayed by the width of the StackPanel, they are cut off and not displayed.

WrapPanel

The WrapPanel is similar to the StackPanel in that controls are positioned in either a stack or row based on the Orientation property. In addition to stacking, the WrapPanel provides wrapping support for contained controls. Thus if more controls are added to a WrapPanel than can be displayed by the width of the WrapPanel, they are wrapped around to form an additional stack or row.

DockPanel

The DockPanel provides docking support for the easy positioning of toolbars or other controls that you want to dock to a side of the panel. The DockPanel control provides a property named DockStyle to contained controls that determines how they will be positioned. Por exemplo, um controle com o DockStyle propriedade definida como DockStyle.Top será ancorada na parte superior da DockPanel. DockPaneltambém expõe uma propriedade chamada LastChildFill. When this property is true, the last child control added to the DockPanel automatically has its DockStyle property set to true.

TabControl

O deTabControlclasse contém vários itens da guia que compartilham o mesmo espaço na tela. Você pode adicionar e remover itens da guia usando o WPF Designer. For more information, see Como: Adicionar itens de guia a um TabControl.

Consulte também

Outros recursos

Controles contêiner

Grid

Tela

StackPanel

WrapPanel

DockPanel

TabControl