title: DrawingVisual not showing in WPF Canvas inside a Window
body: <p>I created a minimal project in order to "get going" with drawing with DrawingVisuals in WPF (being very beginner so far).</p>
  
  <p>My project contains only XAML and code behind for the main window. The only purpose of this project is open a window and display some "signal noise" filling the available space.</p>
  
  <p>MainWindow.xaml is this:</p>
  
  <pre><code>&lt;Window x:Class="MinimalPlotter.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:MinimalPlotter"
          Title="MainWindow" Width="1200" Height="800"
          WindowStartupLocation="CenterScreen"&gt;
  
          &lt;Canvas Height="500" Width="700" x:Name="drawingArea" Margin="50" Background="Gray"&gt;
              &lt;local:VisualHost Canvas.Top="0" Canvas.Left="0" x:Name="host" Width="700" Height="500" /&gt;
          &lt;/Canvas&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And code behind is this:</p>
  
  <pre><code>namespace MinimalPlotter
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
      }
  
      public class VisualHost : FrameworkElement
      {
  
          public VisualHost()
          {
              int h = (int)this.Height;
              int w = (int)this.Width;
  
              Random random = new Random();
              double r;
  
              DrawingVisual path = new DrawingVisual();
  
              StreamGeometry g = new StreamGeometry();
              StreamGeometryContext cr = g.Open();
              cr.BeginFigure(new Point(0,0), false, false);
              for (int i = 0; i &lt; w; i++)
              {
                  // ugly calculations below to get the signal centered in container
                  r = (random.NextDouble()-0.5) * h -h/2;
                  cr.LineTo(new Point(i, r), true, false);
              }
              cr.Close();
              g.Freeze();
  
              DrawingContext crx = path.RenderOpen();
              Pen p = new Pen(Brushes.Black, 2);
              crx.DrawGeometry(null, p, g);
  
              // Ellipse included for "visual debugging"
              crx.DrawEllipse(Brushes.Red, p, new Point(50,50), 45, 20);
  
              crx.Close();
  
              this.AddVisualChild(path);
          }
      }
  }
  </code></pre>
  
  <p>The problem is: when the window opens, the Canvas shows up in the center, as expected (with a gray background), but no signal gets plotted. A previous version of this code worked fine using Path geometry, but with DrawingVisual no geometry is shown (not even the ellipse geometry included for debugging).</p>
  
  <p>Thanks for reading!</p>