title: WPF: Select child control within a Canvas
body: <p>A quick question regarding WPF: How can I select child elements within a Canvas/Grid?</p>
  
  <p>For example, in the following XAML snippet:</p>
  
  <pre><code>    &lt;Canvas Name="parentCanvas" Width="200" Height="200" Background="AliceBlue" MouseMove="parentCanvas_MouseMove" MouseLeave="parentCanvas_MouseLeave"&gt;
          &lt;Border Name="border1" Margin="10" Height="100" Width="180" Background="Maroon" Canvas.Top="47" /&gt;
      &lt;/Canvas&gt;
  </code></pre>
  
  <p>...how can I access <code>border1</code> within <code>parentCanvas_MouseMove</code> and <code>parentCanvas_MouseLeave</code> methods?</p>
  
  <p>Also, the way I access the canvas itself within the event handlers looks a bit hacky, I do something along the lines of:</p>
  
  <pre><code>    private void parentCanvas_MouseLeave(object sender, MouseEventArgs e)
      {
          Canvas c = (Canvas)sender;
          c.Background = Brushes.Blue;
      }
  </code></pre>
  
  <p>Is that the right way of accessing it or is there a more elegant way of doing this?</p>
  
  <p>Many thanks,<br>
  Hamza.</p>