It is obvious, because Screen
is inside System.Windows.Forms
and you do not have access to it from WPF application.
I suppose you are trying to take screenshot so it meight help you in WPF:
private void TakeScreenShot()
{
double Left = SystemParameters.VirtualScreenLeft;
double Top = SystemParameters.VirtualScreenTop;
double ScreenWidth = SystemParameters.VirtualScreenWidth;
double ScreenHeight = SystemParameters.VirtualScreenHeight;
using (System.Drawing.Bitmap bmpScreen = new System.Drawing.Bitmap((int)ScreenWidth, (int)ScreenHeight))
{
using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bmpScreen))
{
graphic.CopyFromScreen((int)Left, (int)Top, 0, 0, bmpScreen.Size);
bmpScreen.Save(@"D:\bitmap.bmp");
IMG.Source = BitmapToImageSource(bmpScreen); // show bitmap in IMG (Image control)
}
}
}
BitmapImage BitmapToImageSource(Bitmap bitmap)
{
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
memory.Position = 0;
BitmapImage bitmapimage = new BitmapImage();
bitmapimage.BeginInit();
bitmapimage.StreamSource = memory;
bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
bitmapimage.EndInit();
return bitmapimage;
}
}
you might need to add a reference to System.Drawing.dll
Updated the answer based on Comment from @Erno de Weerd.
Besides a method to show a bitmap in the image control also added