title: How to identify position of a button with respect to a grid which contains a set of buttons
body: <p>I am a beginner at using WPF.</p>
  
  <p>I have wrote some xaml code in order to make a tic tac toe game.</p>
  
  <p>I have a grid with 3 x 3 cells. I have put a button inside each cell of the grid.</p>
  
  <p>I want to print out the position of the button with respect to the grid(i.e. row number and column number) when I press the button.</p>
  
  <p>This is the xaml code : </p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Test Window" Height="500" Width="500" BorderBrush="#FA0D0D0D"&gt;
  
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition /&gt;
          &lt;RowDefinition /&gt;
          &lt;RowDefinition /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition /&gt;
          &lt;ColumnDefinition /&gt;
          &lt;ColumnDefinition /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Button Name ="b1" Grid.Column=" 0" Grid.Row=" 0" Click="button_Click" /&gt;
      &lt;Button Name ="b2" Grid.Column=" 0" Grid.Row=" 1" Click="button_Click" /&gt;
      &lt;Button Name ="b3" Grid.Column=" 0" Grid.Row=" 2" Click="button_Click" /&gt;
      &lt;Button Name ="b4" Grid.Column=" 1" Grid.Row=" 0" Click="button_Click" /&gt;
      &lt;Button Name ="b5" Grid.Column=" 1" Grid.Row=" 1" Click="button_Click" /&gt;
      &lt;Button Name ="b6" Grid.Column=" 1" Grid.Row=" 2" Click="button_Click" /&gt;
      &lt;Button Name ="b7" Grid.Column=" 2" Grid.Row=" 0" Click="button_Click" /&gt;
      &lt;Button Name ="b8" Grid.Column=" 2" Grid.Row=" 1" Click="button_Click" /&gt;
      &lt;Button Name ="b9" Grid.Column=" 2" Grid.Row=" 2" Click="button_Click" /&gt;
  
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>This is the C# code : </p>
  
  <pre><code>namespace WpfApplication1
  {
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
      static int symbol;
      static int[][] game;
      public MainWindow()
      {
          InitializeComponent();
          symbol = 1;
          game = new int[3][];
          game[0] = new int[3];
          game[1] = new int[3];
          game[2] = new int[3];
  
      }
  
      private void button_Click(object sender, RoutedEventArgs e)
      {
          Button b = (Button)sender;
          if (symbol == 1)
          {
              b.Content = "x";
              symbol = 2;
          }
          else
          {
              b.Content = "o";
              symbol = 1;
          }
      }
  
  
  
  }
  
  }
  </code></pre>
  
  <p>Inside the <code>button_Click</code> method I want to print the row number and column number of the grid, where that button is placed. How can I obtain that information?</p>