title: How to draw a rectangle on a WPF canvas
body: <p>I'm trying to draw a <code>Rectangle</code> on a <code>Canvas</code> as follows:</p>
  
  <pre><code>System.Windows.Shapes.Rectangle rect;
  rect = new System.Windows.Shapes.Rectangle();
  rect.Stroke = new SolidColorBrush(Colors.Black);
  rect.Fill = new SolidColorBrush(Colors.Black);
  rect.Width=200;
  rect.Height=200;
  Canvas.SetLeft(rect,0);
  Canvas.SetTop(rect,0);
  front_canvas.Children.Add(rect);
  </code></pre>
  
  <p>Why would this code not draw a rectangle? </p>
  
  <p>The canvas is defined in the associated XAML as follows:</p>
  
  <pre><code>&lt;Canvas Height="200" Width="200" Name="front_canvas" Grid.Row="1" Grid.Column="0"&gt;      
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>The canvas shows up fine. I can tell because of the gap it leaves in the layout grid.</p>