Grid.GetRow Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the value of the Grid.Row attached property from the specified FrameworkElement.
Assembly: System.Windows (in System.Windows.dll)
Parameters
- element
- Type: System.Windows.FrameworkElement
The element from which to read the property value.
The following example shows how to get the row of the element that raised an event.
<Grid x:Name="LayoutRoot" Background="Transparent" ShowGridLines="True" > <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Rectangle Fill="White" Height="100" Width="100" Grid.Row="0" Grid.Column="0" MouseEnter="r1_MouseEnter"/> <Rectangle Fill="Yellow" Height="100" Width="100" Grid.Row="0" Grid.Column="1" MouseEnter="r1_MouseEnter" /> <Rectangle Fill="Blue" Height="100" Width="100" Grid.Row="1" Grid.Column="0" MouseEnter="r1_MouseEnter" /> <Rectangle Fill="Green" Height="100" Width="100" Grid.Row="1" Grid.Column="1" MouseEnter="r1_MouseEnter"/> <StackPanel > <StackPanel Orientation="Horizontal" > <TextBlock Text="Row = " /> <TextBlock x:Name="txtRow" /> </StackPanel> <StackPanel Orientation="Horizontal" > <TextBlock Text="Column = " /> <TextBlock x:Name="txtCol" /> </StackPanel> </StackPanel> </Grid>
private void r1_MouseEnter(object sender, MouseEventArgs e) { Rectangle r = (Rectangle)sender; int row = Grid.GetRow(r); int col = Grid.GetColumn(r); txtRow.Text = row.ToString(); txtCol.Text = col.ToString(); }
The preceding example produces output that is similar to the following illustration.

Show: