private void TakeScreenShot(String fileName)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(this);
double dpi = 96d;
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height,
dpi, dpi, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(this);
dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}
renderBitmap.Render(dv);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
using (FileStream file = File.Create(fileName))
{
encoder.Save(file);
}
appShotLocLabel.Content = String.Format("Screenshot saved to: {0}", fileName);
((System.Windows.Media.Animation.Storyboard)FindResource("autoFade")).Begin(appShotLocLabel);
}