Grid.GetColumn(FrameworkElement) Método

Definição

Obtém o valor da propriedade anexada Grid.Column XAML do FrameworkElement especificado.

public:
 static int GetColumn(FrameworkElement ^ element);
 static int GetColumn(FrameworkElement const& element);
public static int GetColumn(FrameworkElement element);
function getColumn(element)
Public Shared Function GetColumn (element As FrameworkElement) As Integer

Parâmetros

element
FrameworkElement

O elemento do qual o valor da propriedade é lido.

Retornos

Int32

int

O valor da propriedade anexada Grid.Column XAML no elemento de destino. Esse é um índice baseado em zero.

Exemplos

O exemplo a seguir mostra como obter a linha e a coluna do elemento que gerou um evento.

<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();
    
}

Comentários

Esse método é um método utilitário para o sistema de propriedades e não é usado na maioria dos cenários de aplicativo. Na maioria dos casos, você define a propriedade anexada Grid.Column XAML em XAML e não precisará desse método. Para obter mais informações, consulte a propriedade anexada Grid.Column XAML.

Aplica-se a

Confira também