Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RowDefinition Class

Defines row-specific properties that apply to Grid elements.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

'Declaration
Public Class RowDefinition
	Inherits DefinitionBase
'Usage
Dim instance As RowDefinition

public class RowDefinition extends DefinitionBase
public class RowDefinition extends DefinitionBase
<RowDefinition .../>

You must set a RowDefinition for each row in a Grid. When you set a row-specific RowDefinition, you assign unique sizing properties to each row.

To set a group of RowDefinition elements by using code, add the RowDefinition to a RowDefinitionCollection.

The RowDefinition class exposes only height properties. To set width properties in a Grid, create an instance of ColumnDefinition.

The following example shows how to create and use an instance of Grid by using either Extensible Application Markup Language (XAML) or code. This example uses three ColumnDefinitions and three RowDefinitions to create a grid that has nine cells, such as in a worksheet. Each cell contains a TextBlock element that represents data, and the top row contains a TextBlock with the ColumnSpan property applied. To show the boundaries of each cell, the ShowGridLines property is enabled.

Public Sub New()
    WindowTitle = "Grid Sample"
    'Create a Grid as the root Panel element
    Dim myGrid As New Grid()
    myGrid.Height = 100
    myGrid.Width = 250
    myGrid.ShowGridLines = True
    myGrid.HorizontalAlignment = Windows.HorizontalAlignment.Left
    myGrid.VerticalAlignment = Windows.VerticalAlignment.Top

    ' Define and Add the Rows and Columns
    Dim colDef1 As New ColumnDefinition
    Dim colDef2 As New ColumnDefinition
    Dim colDef3 As New ColumnDefinition
    myGrid.ColumnDefinitions.Add(colDef1)
    myGrid.ColumnDefinitions.Add(colDef2)
    myGrid.ColumnDefinitions.Add(colDef3)

    Dim rowDef1 As New RowDefinition
    Dim rowDef2 As New RowDefinition
    Dim rowDef3 As New RowDefinition
    Dim rowDef4 As New RowDefinition
    myGrid.RowDefinitions.Add(rowDef1)
    myGrid.RowDefinitions.Add(rowDef2)
    myGrid.RowDefinitions.Add(rowDef3)
    myGrid.RowDefinitions.Add(rowDef4)

    Dim txt1 As New TextBlock
    txt1.Text = "2004 Products Shipped"
    txt1.FontSize = 20
    txt1.FontWeight = FontWeights.Bold
    Grid.SetColumnSpan(txt1, 3)
    Grid.SetRow(txt1, 0)
    myGrid.Children.Add(txt1)

    Dim txt2 As New TextBlock
    txt2.Text = "Quarter 1"
    txt2.FontSize = 12
    txt2.FontWeight = FontWeights.Bold
    Grid.SetRow(txt2, 1)
    Grid.SetColumn(txt2, 0)
    myGrid.Children.Add(txt2)

    Dim txt3 As New TextBlock
    txt3.Text = "Quarter 2"
    txt3.FontSize = 12
    txt3.FontWeight = FontWeights.Bold
    Grid.SetRow(txt3, 1)
    Grid.SetColumn(txt3, 1)
    myGrid.Children.Add(txt3)

    Dim txt4 As New TextBlock
    txt4.Text = "Quarter 3"
    txt4.FontSize = 12
    txt4.FontWeight = FontWeights.Bold
    Grid.SetRow(txt4, 1)
    Grid.SetColumn(txt4, 2)
    myGrid.Children.Add(txt4)

    Dim txt5 As New TextBlock
    txt5.Text = "50,000"
    Grid.SetRow(txt5, 2)
    Grid.SetColumn(txt5, 0)
    myGrid.Children.Add(txt5)

    Dim txt6 As New Controls.TextBlock
    txt6.Text = "100,000"
    Grid.SetRow(txt6, 2)
    Grid.SetColumn(txt6, 1)
    myGrid.Children.Add(txt6)

    Dim txt7 As New TextBlock
    txt7.Text = "150,000"
    Grid.SetRow(txt7, 2)
    Grid.SetColumn(txt7, 2)
    myGrid.Children.Add(txt7)

    ' Add the final TextBlock Cell to the Grid
    Dim txt8 As New TextBlock
    txt8.FontSize = 16
    txt8.FontWeight = FontWeights.Bold
    txt8.Text = "Total Units: 300000"
    Grid.SetRow(txt8, 3)
    Grid.SetColumnSpan(txt8, 3)
    myGrid.Children.Add(txt8)

    Me.Content = myGrid
End Sub

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Grid Sample">
    <Grid VerticalAlignment="Top" HorizontalAlignment="Left" ShowGridLines="True" Width="250" Height="100">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>

      <TextBlock FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0">2005 Products Shipped</TextBlock>
      <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="0">Quarter 1</TextBlock>
      <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="1">Quarter 2</TextBlock>
      <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="2">Quarter 3</TextBlock>
      <TextBlock Grid.Row="2" Grid.Column="0">50000</TextBlock>
      <TextBlock Grid.Row="2" Grid.Column="1">100000</TextBlock>
      <TextBlock Grid.Row="2" Grid.Column="2">150000</TextBlock>
      <TextBlock FontSize="16" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="3">Total Units: 300000</TextBlock>
    </Grid>
</Page>

More Code

How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections

This example shows how to use the methods in the ColumnDefinitionCollection and RowDefinitionCollection classes to perform actions like adding, clearing, or counting the contents of rows or columns. For example, you can Add, Clear, or Count the items that are included in a ColumnDefinition or RowDefinition. To view the complete sample, see Manipulating Row and Column Collections Sample.

How to: Create and Use a GridLengthConverter Object

The following example shows how to create and use an instance of GridLengthConverter. The example defines a custom method called changeCol, which passes the ListBoxItem to a GridLengthConverter that converts the Content of a ListBoxItem to an instance of GridLength. The converted value is then passed back as the value of the Width property of the ColumnDefinition element.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft