* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
2.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections | 03/30/2017 |
|
|
bfc7160a-45f2-4e17-9961-df414dfb13c5 |
How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections
This example shows how to use the methods in the xref:System.Windows.Controls.ColumnDefinitionCollection and xref:System.Windows.Controls.RowDefinitionCollection classes to perform actions like adding, clearing, or counting the contents of rows or columns. For example, you can xref:System.Windows.Controls.ColumnDefinitionCollection.Add%2A, xref:System.Windows.Controls.ColumnDefinitionCollection.Clear%2A, or xref:System.Windows.Controls.ColumnDefinitionCollection.Count%2A the items that are included in a xref:System.Windows.Controls.ColumnDefinition or xref:System.Windows.Controls.RowDefinition.
Example
The following example creates a xref:System.Windows.Controls.Grid element with a xref:System.Windows.FrameworkElement.Name%2A of grid1. The xref:System.Windows.Controls.Grid contains a xref:System.Windows.Controls.StackPanel that holds xref:System.Windows.Controls.Button elements, each controlled by a different collection method. When you click a xref:System.Windows.Controls.Button, it activates a method call in the code-behind file.
[!code-xamlColumnDefinitionsGrid#1]
This example defines a series of custom methods, each corresponding to a xref:System.Windows.Controls.Primitives.ButtonBase.Click event in the [!INCLUDETLA#tla_xaml] file. You can change the number of columns and rows in the xref:System.Windows.Controls.Grid in several ways, which includes adding or removing rows and columns; and counting the total number of rows and columns. To prevent xref:System.ArgumentOutOfRangeException and xref:System.ArgumentException exceptions, you can use the error-checking functionality that the xref:System.Windows.Controls.ColumnDefinitionCollection.RemoveRange%2A method provides.
[!code-csharpColumnDefinitionsGrid#2] [!code-vbColumnDefinitionsGrid#2]