title: How to take a screenshot of a WPF control?
body: <p>I created a WPF application using the Bing maps WPF control.
  I would like to be able to screenshot only the Bing maps control.</p>
  
  <p>Is use this code to make the screenshot:</p>
  
  <pre><code>// Store the size of the map control
  int Width = (int)MyMap.RenderSize.Width;
  int Height = (int)MyMap.RenderSize.Height;
  System.Windows.Point relativePoint = MyMap.TransformToAncestor(Application.Current.MainWindow).Transform(new System.Windows.Point(0, 0));
  int X = (int)relativePoint.X;
  int Y = (int)relativePoint.Y;
  
  Bitmap Screenshot = new Bitmap(Width, Height);
  Graphics G = Graphics.FromImage(Screenshot);
  // snip wanted area
  G.CopyFromScreen(X, Y, 0, 0, new System.Drawing.Size(Width, Height), CopyPixelOperation.SourceCopy);
  
  string fileName = "C:\\myCapture.bmp";
  System.IO.FileStream fs = System.IO.File.Open(fileName, System.IO.FileMode.OpenOrCreate);
  Screenshot.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
  fs.Close();
  </code></pre>
  
  <p><strong>My problem:</strong></p>
  
  <p>The <code>Width</code> and <code>Height</code> appear to be bad (false values).
  The screenshot produced appear to use bad coordinates.</p>
  
  <p><strong>My screenshot:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/J351U.png" alt="My screenshot"></p>
  
  <p><strong>What I expect:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/vCDGs.jpg" alt="Desired screenshot"></p>
  
  <p>Why do I get this result?
  I tried in Release mode, and without Visual Studio, result is the same.</p>