Compartilhar via


Como: Remover Linhas e Colunas de uma Grade

The Windows Presentation Foundation (WPF) Grid control enables you to easily position and align controls by creating grid-based layouts. At design time, you can remove rows and columns from a Grid control in the WPF Designer for Visual Studio.

When you delete a row or a column, you must reposition any controls that were in that row or column. You can do this by modifying the Grid.Row or Grid.Column properties of the affected controls.

Este tópico aborda três maneiras que você pode excluir linhas e colunas de uma Grid. Para obter informações sobre como adicionar linhas e colunas a uma grade, consulte Como: adicionar linhas e colunas para uma grade.

Using the Designer

Você pode remover existente de linhas e colunas de uma Grid o controle no modo de exibição de Design.

Para excluir linhas e colunas em uma grade usando o designer

  1. No WPF Designer, selecione um Grid controle que tem pelo menos duas colunas ou duas linhas.

  2. Mova o ponteiro sobre um indicador de linha de grade no condutor de grade.

    O indicador de linha de grade fica laranja e oponteiro do mousemuda para indicar o reposicionamento.

  3. Arraste o indicador de linha de grade fora da grade.

    Quando você clicar, a linha de grade e o indicador de linha de grade ficam vermelhos. Depois de você ter arrastado para fora da grade, oponteiro do mousemuda e inclui um x para indicar a exclusão.

  4. Solte o botão do mouse.

    A linha de grade e correspondente de linha ou coluna é removida. As propriedades de linhas e colunas restantes são atualizadas adequadamente.

Using the Collection Editor

You can delete rows and columns from a Grid by using the collection editor. When you use the collection editor to configure rows and columns, Design view and XAML view are updated automatically.

To delete rows from a grid by using the collection editor

  1. In the WPF Designer, select a Grid control.

  2. In the Properties window, locate the RowDefinitions property, and click the ellipsis button in the property value column.

    The Collection Editor dialog box appears.

  3. In the left pane click the RowDefinition that you want to delete.

  4. Click Remove item to delete the row.

  5. (Optional) Repeat steps 3 and 4 to delete more rows.

  6. Click OK to close the Collection Editor and return to the WPF Designer.

To delete columns from a grid by using the collection editor

  1. In the WPF Designer, select a Grid control.

  2. In the Properties window, locate the ColumnDefinitions property, and click the ellipsis button in the property value column.

    The Collection Editor dialog box appears.

  3. In the left pane click the ColumnDefinition that you want to delete.

  4. Click Remove item to delete the column.

  5. (Optional) Repeat steps 3 and 4 to delete more columns.

  6. Click OK to close the Collection Editor and return to the WPF Designer.

Using the XAML Editor

You can also remove rows and columns from a Grid manually by deleting them in the XAML editor. Design view is automatically updated.

To delete rows and columns from a grid by using the XAML editor

  1. In the XAML editor, locate a Grid element that contains rows and columns. The following markup shows an example:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="5*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="5*" />
        </Grid.ColumnDefinitions>
    </Grid>
    
  2. Delete the rows and columns that you no longer need.

Consulte também

Tarefas

Passo a passo: Construindo um layout dinâmico

Conceitos

Alinhamento no WPF Designer

Layout com absoluto e dinâmica posicionamento

Outros recursos

Controles contêiner