title: How to capture a image of WindowsFormsHost in wpf using c#
body: <p>I have a WindowsFormsHost panel in a WPF application on which graphics are drawn via third party dll. I want to capture the hosted panel. I tried it using {RenderTargetBitmap} but it dint work and only saving grid behind the panel. </p>
  
  <p>I also tried it using {DrawToBitmap} method as below but it is only giving empty white area. </p>
  
  <pre><code>path = @"E:\\whatever\\test.png";
  var bmp = new System.Drawing.Bitmap((int)MyUserControl.myPanel.Width,(int)MyUserControl.myPanel.Height);
  MyUserControl.myPanel.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
  bmp.Save(path, System.Drawing.Imaging.ImageFormat.Png);
  </code></pre>
  
  <p>Note that this panel is added in codebehind and not in xaml designer.</p>
  
  <p>What am I doing wrong or is there any other solution? Any help. I could find similar questions but not answer.</p>
  
  <p>Edit: Also I do not want to copy from screen. Let me know if this is possible at all?</p>