title: WPF: Take a screenshot and save it
body: <p>I'm new to WPF applications and I've tried looking around to see if I could find something that works for this, but so far nothing I've found works (I guess it's because most of it is outdated). I want to take a screenshot of the entire desktop (i.e. all monitors) and save it as a <code>.jpg</code> to a specific folder with the time and date as the file name when I click the screenshot button. I was able to achieve this in my Windows Forms application, but haven't been able to do so with my WPF application.</p>
  
  <p>This is the code that I used for my Windows Forms application.</p>
  
  <pre><code>int screenLeft = SystemInformation.VirtualScreen.Left;
  int screenTop = SystemInformation.VirtualScreen.Top;
  int screenWidth = SystemInformation.VirtualScreen.Width;
  int screenHeight = SystemInformation.VirtualScreen.Height;
  
  using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
  {
      using (Graphics g = Graphics.FromImage(bmp))
      {
          String filename = "ScreenCapture-" + DateTime.Now.ToString("ddMMyyyy-hhmmss") + ".png";
          Opacity = .0;
          g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
          bmp.Save("C:\\ScreenShots\\" + filename);
          Opacity = 1;
      }
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>