title: Generate BitmapSource from UIElement
body: <p>I am attempting to generate a <code>BitmapFrame</code> that is based on a <code>UIElement</code>. Here is my function:</p>
  
  <pre><code>private BitmapFrame RenderToBitmap2()
  {
      RenderTargetBitmap renderBitmap = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
  
      DrawingVisual drawingVisual = new DrawingVisual();
      DrawingContext drawingContext = drawingVisual.RenderOpen();
      VisualBrush aVisualBrush = new VisualBrush(GenerateTestStackPanel());
      drawingContext.DrawRectangle(aVisualBrush, new Pen(Brushes.Green, 2), new Rect(new Size(150, 150)));
  
      drawingContext.Close();
  
      renderBitmap.Render(drawingVisual);
  
      return BitmapFrame.Create(renderBitmap);
  }
  </code></pre>
  
  <p>For testing and debugging purposes, I am using an additional function that creates a simple StackFrame that <em>should</em> create a valid visual element that can be represented:</p>
  
  <pre><code>private StackPanel GenerateTestStackPanel()
  {
      // Create a red Ellipse.
      Ellipse myEllipse = new Ellipse();
  
      myEllipse.Fill = Brushes.Green;
      myEllipse.StrokeThickness = 2;
      myEllipse.Stroke = Brushes.Black;
  
      // Set the width and height of the Ellipse.
      myEllipse.Width = 200;
      myEllipse.Height = 200;
      // Add the Ellipse to the StackPanel.
      StackPanel myStackPanel = new StackPanel();
      myStackPanel.Children.Add(myEllipse);
      return myStackPanel;
  }
  </code></pre>
  
  <p>For some reason, the VisualBrush is not being rendered in the DrawRetangle(...) function. I can see the green border but nothing else. In addition, if I swap out the VisualBrush with a standard brush, it works great:</p>
  
  <pre><code>drawingContext.DrawRectangle(Brushes.Plum, new Pen(Brushes.Green, 2), new Rect(new Size(150, 150)));
  </code></pre>
  
  <p>Thanks in advance!</p>