title: Get the clicked rectangle in 2d array
body: <p>I have a 2D array that contains rectangles. They are stored in a dynamic UniformGrid. How do I find out which rectangle in the array was MouseDown?</p>
  <p>I tried this but I keep getting [0,0]:</p>
  <pre class="lang-cs prettyprint-override"><code>if (e.OriginalSource is Shape s)
  {
      cellRow = (int)s.GetValue(Grid.RowProperty);
      cellColumn = (int)s.GetValue(Grid.ColumnProperty);
      rectangle[cellRow,cellColumn].Fill = new SolidColorBrush(Colors.Black);
  }
  </code></pre>
  <p>And this is how I generated the rectangles:</p>
  <pre class="lang-cs prettyprint-override"><code>rectangle = new Rectangle[rowcol, rowcol];
  for (int x = 0; x &lt; rowcol; x++)
  {
      for (int y = 0; y &lt; rowcol; y++)
      {
          rectangle[y, x] = new Rectangle { Stroke = Brushes.Black, StrokeThickness = 0.5, Fill = Brushes.White };
          GameUniformGrid.Children.Add(rectangle[y, x]);
      }
  }
  </code></pre>
  <p>The MouseDown event in xaml:
  <code>&lt;UniformGrid x:Name=&quot;GameUniformGrid&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;272&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;272&quot; Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; Rectangle.MouseDown=&quot;ToggleGrid&quot;/&gt;</code></p>