title: How do I save all content of a WPF ScrollViewer as an image
body: <p>I have a WPF window with a ScrollViewer control containing many child controls that extend vertically.  When a user clicks a button located at the bottom of the ScrollViewer I would like all the content (currently in view and out of view) to be saved as an image.</p>
  
  <p>I am using the following code which I have adapted from examples showing how to save the content of a Window:</p>
  
  <pre><code>public static void SaveForm(ScrollViewer container, string filename)
  {        
      const int dpi = 96;
      var rtb = new RenderTargetBitmap(
          (int)container.ExtentWidth, //width 
          (int)container.ExtentHeight, //height 
          dpi, //dpi x 
          dpi, //dpi y 
          PixelFormats.Pbgra32 // pixelformat 
          );
  
      rtb.Render(container);
      SaveRTBAsPNG(rtb, filename);
  }
  
  private static void SaveRTBAsPNG(RenderTargetBitmap bmp, string filename)
  {
      var enc = new System.Windows.Media.Imaging.PngBitmapEncoder();
      enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp));
  
      using (var stm = System.IO.File.Create(filename))
      {
          enc.Save(stm);
      }
  }
  </code></pre>
  
  <p>Currently a PNG is being produced but it only has the currently visible portion of the ScrollViewer.  Is there any way I can get the PNG to contain all of the content, including that which needs to be scrolled into view?</p>