Grid.GetColumn(FrameworkElement) Grid.GetColumn(FrameworkElement) Grid.GetColumn(FrameworkElement) Grid.GetColumn(FrameworkElement) Method


Gets the value of the Grid.Column XAML attached property from the specified FrameworkElement.

public : static int GetColumn(FrameworkElement element)
static int32_t GetColumn(FrameworkElement element) const;
public static int GetColumn(FrameworkElement element)
Public Shared Function GetColumn(element As FrameworkElement) As int


FrameworkElement FrameworkElement

The element from which to read the property value.


int int

The value of the Grid.Column XAML attached property on the target element. This is a zero-based index.


The following example shows how to get the row and column of the element that raised an event.

<Grid x:Name="LayoutRoot">
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="Black"/>
        <ColumnDefinition />
        <ColumnDefinition />
        <RowDefinition />
        <RowDefinition />  
    <Rectangle Fill="White" Height="100" Width="100" Grid.Row="0" Grid.Column="0" 
    <Rectangle Fill="Yellow" Height="100" Width="100" Grid.Row="0" Grid.Column="1" 
               PointerEntered="r1_PointerEntered" />
    <Rectangle Fill="Blue" Height="100" Width="100" Grid.Row="1" Grid.Column="0" 
               PointerEntered="r1_PointerEntered" />
    <Rectangle Fill="Green" Height="100" Width="100" Grid.Row="1" Grid.Column="1" 
    <StackPanel >
        <StackPanel Orientation="Horizontal" >
        <TextBlock Text="Row = " />
        <TextBlock x:Name="txtRow"  />
    <StackPanel Orientation="Horizontal" >
        <TextBlock Text="Column = " />
        <TextBlock x:Name="txtCol"  />
private void r1_PointerEntered(object sender, PointerRoutedEventArgs e)
    Rectangle r = (Rectangle)sender;
    int row = Grid.GetRow(r);
    int col = Grid.GetColumn(r);

    txtRow.Text = row.ToString();
    txtCol.Text = col.ToString();


This method is a utility method for the property system, and isn't used in most app scenarios. In most cases you set the Grid.Column XAML attached property in XAML and won't need this method. For more info, see the Grid.Column XAML attached property.

See also