Grid.GetColumn method

Applies to Windows and Windows Phone

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

Syntax


public static int GetColumn(
  FrameworkElement element
)

Parameters

element

Type: FrameworkElement

The element from which to read the property value.

Return value

Type: System.Int32 [.NET] | int32 [C++]

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

Remarks

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.

Examples

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


<Grid x:Name="LayoutRoot">
    <Grid.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="Black"/>
        </Style>
    </Grid.Resources>
    <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" 
               PointerEntered="r1_PointerEntered"/>
    <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" 
               PointerEntered="r1_PointerEntered"/>
    <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_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();
    
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

Grid
Grid.Column

 

 

Show:
© 2014 Microsoft