Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to grab row and column info from a label inside a grid in WPF?
    text
    copied!<p>I have a 3x3 grid that I use as a gameboard for tic tac toe. Each grid has a label that can display "X" "O" or "". Each of these labels contains row and column information for where they are located to. I am trying to get that information from code file. So far I have:</p> <pre><code> &lt;Label Grid.Row="0" Grid.Column="0" Name="lblZeroxZero" MouseDown="lblZeroxZero_MouseDown" FontSize="72" Padding="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt; &lt;Label Grid.Row="0" Grid.Column="1" Name="lblZeroxOne" MouseDown="lblZeroxOne_MouseDown" FontSize="72" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" /&gt; &lt;Label Grid.Row="0" Grid.Column="2" Name="lblZeroxTwo" MouseDown="lblZeroxTwo_MouseDown" VerticalContentAlignment="Center" FontSize="72" HorizontalContentAlignment="Center" /&gt; &lt;Label Grid.Row="1" Grid.Column="0" Name="lblOnexZero" MouseDown="lblOnexZero_MouseDown" HorizontalContentAlignment="Center" FontSize="72" VerticalContentAlignment="Center" /&gt; &lt;Label Grid.Row="1" Grid.Column="1" Name="lblOnexOne" MouseDown="lblOnexOne_MouseDown" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="72" /&gt; &lt;Label Grid.Row="1" Grid.Column="2" Name="lblOnexTwo" MouseDown="lblOnexTwo_MouseDown" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="72" /&gt; &lt;Label Grid.Row="2" Grid.Column="0" Name="lblTwoxZero" MouseDown="lblTwoxZero_MouseDown" FontSize="72" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" /&gt; &lt;Label Grid.Row="2" Grid.Column="1" Name="lblTwoxOne" MouseDown="lblTwoxOne_MouseDown" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="72" /&gt; &lt;Label Grid.Row="2" Grid.Column="2" Name="lblTwoxTwo" MouseDown="lblTwoxTwo_MouseDown" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="72"&gt; </code></pre> <p>Those are my labels and in my code file I want to get the Grid.Row and Grid.Column info. When I type lblZeroxZero. the intellisense doesn't bring up any properties that contain the row and column information. Does anyone know how to get this info? Do I have to access it from the datagrid as opposed to the label?</p> <p>Edit: Some more info</p> <p>In my codefile I have this method (not complete yet)</p> <pre><code> private int[] GetLabelPosition(Label lbl) { int[] rowColumnInfo = new int[2]; if (lbl.Name == "lblZeroxZero") { rowColumnInfo[0] = 0; rowColumnInfo[1] = 0; } else if (lbl.Name == "lblOnexZero") { rowColumnInfo[0] = 1; rowColumnInfo[1] = 0; } return rowColumnInfo; } </code></pre> <p>Currently, the only way I know how to get the label's row and column info is by looking at its name. I would like to get the Grid.Row and Grid.Column information without having to create a bunch of specific cases for each label name.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload