title: WPF RenderTargetBitmap with Viewport3D
body: <p>I'm loading a XAML UserControl with XamlReader and then I'm trying to convert it to an image with RenderTargetBitmap.</p>
  
  <p>It's working fine with a simple UserControl.</p>
  
  <p>But if I use this Viewport3D, it doesn't work. The image is created without the 3D part... :</p>
  
  <pre><code>    &lt;Viewport3D&gt;
          &lt;ModelVisual3D&gt;
              &lt;ModelVisual3D.Content&gt;
                  &lt;GeometryModel3D&gt;
                      &lt;GeometryModel3D.Geometry&gt;
                          &lt;MeshGeometry3D
                              Positions="-0.5  0.5  -0.5,  0.5  0.5  -0.5,
                                         -0.5  0  0.5,  0.5  0  0.5"
                              TriangleIndices=" 0  2  1,  1  2  3"
                              TextureCoordinates="0 0, 1 0, 0 1, 1 1" /&gt;
                      &lt;/GeometryModel3D.Geometry&gt;
  
                      &lt;GeometryModel3D.Material&gt;
                          &lt;DiffuseMaterial&gt;
                              &lt;DiffuseMaterial.Brush&gt;
                                  &lt;VisualBrush&gt;
                                      &lt;VisualBrush.Visual&gt;
                                          &lt;Button&gt;Hi&lt;/Button&gt;
                                      &lt;/VisualBrush.Visual&gt;
                                  &lt;/VisualBrush&gt;
                              &lt;/DiffuseMaterial.Brush&gt;
                          &lt;/DiffuseMaterial&gt;                              
                      &lt;/GeometryModel3D.Material&gt;
  
                      &lt;!-- Non-Affine Matrix Transform. --&gt;
                      &lt;GeometryModel3D.Transform&gt;
                          &lt;MatrixTransform3D&gt;
                          &lt;/MatrixTransform3D&gt;
                      &lt;/GeometryModel3D.Transform&gt;
  
                  &lt;/GeometryModel3D&gt;
              &lt;/ModelVisual3D.Content&gt;
          &lt;/ModelVisual3D&gt;
  
          &lt;!-- Light sources. --&gt;
          &lt;ModelVisual3D&gt;
              &lt;ModelVisual3D.Content&gt;
                  &lt;Model3DGroup&gt;
                      &lt;AmbientLight Color="#404040" /&gt;
                      &lt;DirectionalLight Color="#C0C0C0" Direction="0 -2 -1" /&gt;
                  &lt;/Model3DGroup&gt;
              &lt;/ModelVisual3D.Content&gt;
          &lt;/ModelVisual3D&gt;
  
          &lt;!-- Camera. --&gt;
          &lt;Viewport3D.Camera&gt;
              &lt;PerspectiveCamera Position="0 0.2 1"
                                 LookDirection="0 0 -1.5"
                                 UpDirection="0 1 0"
                                 FieldOfView="100"&gt;
              &lt;/PerspectiveCamera&gt;
          &lt;/Viewport3D.Camera&gt;
      &lt;/Viewport3D&gt;
  </code></pre>
  
  <p>My method to convert a UserControl to an image :</p>
  
  <pre><code>private static byte[] ConvertUserControlToPng(UserControl userControl)
      {
          userControl.Measure(new Size(userControl.Width, userControl.Height));
          userControl.Arrange(new Rect(new Size(userControl.Width, userControl.Height)));
          var renderTargetBitmap = new RenderTargetBitmap((int)(userControl.Width * 300 / 96),
                                                          (int)(userControl.Height * 300 / 96),
                                                          300, 300, PixelFormats.Pbgra32);
          renderTargetBitmap.Render(userControl);
          BitmapEncoder encoder = new PngBitmapEncoder();
          encoder.Frames.Clear();
          encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
  
          byte[] result;
          using (var stream = new MemoryStream())
          {
              encoder.Save(stream);
              result = stream.ToArray();
          }
          return result;
      }
  </code></pre>
  
  <p>Am I missing something ?</p>