title: Why can I draw points on a Canvas only after the background colour has been set?
body: <p>I have a simple program that implements code discussed in <a href="https://stackoverflow.com/q/1479665">this question</a> to trace mouse movements. However, it seems that the events are only fired if the background colour of the Canvas control is set. </p>
  
  <p>XAML (with the background colour set):</p>
  
  <pre><code>&lt;Window x:Class="SimplePaint.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="501" Width="784"&gt;
      &lt;Grid&gt;
          &lt;Canvas Height="402" HorizontalAlignment="Left" Margin="12,12,0,0" Name="PaintCanvas" VerticalAlignment="Top" Width="738" MouseDown="PaintCanvas_MouseDown" MouseMove="PaintCanvas_MouseMove" MouseUp="PaintCanvas_MouseUp" Background="#FFDEF4FF"&gt;
              &lt;Polyline x:Name="polyline" Stroke="Black" StrokeThickness="3"/&gt;
          &lt;/Canvas&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>private bool drawing = false;
  
  private void PaintCanvas_MouseDown(object sender, MouseButtonEventArgs e)
  {
      this.drawing = true;
  }
  
  private void PaintCanvas_MouseMove(object sender, MouseEventArgs e)
  {
     if (this.drawing)
          polyline.Points.Add(e.GetPosition(this.PaintCanvas));
  }
  
  private void PaintCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  {
      this.drawing = false;
  }
  </code></pre>
  
  <p>This code works. However, if I remove <code>Background="#FFDEF4FF"</code> from the XAML, nothing happens when the program is used. Setting a breakpoint in the event handlers reveals that they do not fire. </p>