Compartilhar via


Como: Criar um layout com base no posicionamento absoluto

O WPF Designer for Visual Studio fornece um Canvas painel de controle que suporte o posicionamento absoluto. You can use the Canvas panel control to position elements absolutely in your applications.

Observação importanteImportante

Whenever possible, it is preferable to use a dynamic layout. Dynamic layouts are the most flexible, adapt to content changes such as localization, and allow the end user the most control over their environment. To see examples of dynamic layouts, see Como: Criar um layout dinâmico and Passo a passo: Construindo um layout dinâmico.

Adding a Panel Control

By default, each new WPF application contains a Window with a Grid panel. To create a layout based on absolute positioning, you must use a Canvas panel. In this procedure you remove the default Grid and add a Canvas.

To add a panel control

  1. In Design view, select the grid.

    ObservaçãoObservação

    You can select the grid in various ways, such as by clicking anywhere inside it or by using the TAB key. For more information about how to select elements in the WPF Designer, see Como: Selecionar e mover elementos na superfície de design.

  2. Press the DELETE key to delete the Grid.

  3. From the Toolbox, in the Controls group, drag a Canvas control onto the Window.

  4. (Optional) In the Properties window, set the Height property of the Canvas to Auto.

    The Canvas stretches to fill the height of the Window.

  5. (Optional) In the Properties window, set the Width property of the Canvas to Auto.

    The Canvas stretches to fill the width of the Window.

  6. On the File menu, click Save All.

Adding Controls to the Panel

Next, you add controls to the panel and use the Left and Top attached properties of the Canvas to position them absolutely.

To add controls to the panel

  1. Do caixa de ferramentas, arraste um controle para o Canvas.

  2. In the Properties window, set the following properties for the control:

    • Canvas.Left

    • Canvas.Top

    ObservaçãoObservação

    Há dois conjuntos de propriedades mutuamente exclusivos: Left/ Right, and Top / Bottom. Only Left and Top are exposed in the Properties window, but you can specify Right and Bottom in the XAML editor. If you specify both Left and Right, only the last declaration is used. If you specify both Top and Bottom, only the last declaration is used.

  3. Repeat steps 1 and 2 until all the necessary controls have been added to the panel.

  4. On the File menu, click Save All.

Consulte também

Tarefas

Passo a passo: Construindo um layout com base no posicionamento absoluto

Conceitos

Layout com absoluto e dinâmica posicionamento

Alinhamento no WPF Designer

Sistema de layout

Visão geral do WPF e do Silverlight Designer

Outros recursos

Walkthroughs de layout