Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Makubex is correct - you need to wait until things get loaded up before the visuals are in a state where they've actually rendered anything capable of being copied; that said, while I'm not on a computer where I've got Studio installed, I <em>do</em> have LINQPad installed....</p> <pre><code>void Main() { mainWindow = new Window(){ Width = 640, Height = 480, Title = "Main Window" }; canvas = new Canvas { Width = 640, Height = 480 }; System.Windows.Size size = new System.Windows.Size( canvas.Width, canvas.Height ); // Measure and arrange the surface canvas.Measure( size ); canvas.Arrange( new Rect( size ) ); canvas.Background = new SolidColorBrush( Colors.Purple ); mirrorTimer = new DispatcherTimer( TimeSpan.FromMilliseconds(1000.0 / 60.0), DispatcherPriority.Background, CopyToMirror, Dispatcher.CurrentDispatcher); updateTimer = new DispatcherTimer( TimeSpan.FromMilliseconds(1000.0 / 60.0), DispatcherPriority.Background, DrawSomething, Dispatcher.CurrentDispatcher); mainWindow.Loaded += (o,e) =&gt; { mirrorWindow = new Window { Width = 640, Height = 480, Title = "Mirror Window" }; mirrorWindow.Show(); mirrorWindow.Loaded += (o2,e2) =&gt; { mirrorTimer.Start(); }; }; mainWindow.Closed += (o,e) =&gt; { if(mirrorTimer != null) { mirrorTimer.Stop(); mirrorWindow.Close(); } }; mainWindow.Content = canvas; mainWindow.Show(); } Window mainWindow; Window mirrorWindow; Canvas canvas; DispatcherTimer mirrorTimer; DispatcherTimer updateTimer; Random rnd = new Random(); private void DrawSomething(object sender, EventArgs args) { canvas.Children.Clear(); canvas.Background = Brushes.White; var blob = new Ellipse() { Width = rnd.Next(0, 20), Height = rnd.Next(0, 20) }; blob.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)rnd.Next(0,255), (byte)rnd.Next(0,255), (byte)rnd.Next(0,255))); Canvas.SetLeft(blob, (int)rnd.Next(0, (int)canvas.ActualWidth)); Canvas.SetTop(blob, (int)rnd.Next(0, (int)canvas.ActualHeight)); canvas.Children.Add(blob); } private void CopyToMirror(object sender, EventArgs args) { var currentImage = (mirrorWindow.Content as Image); if(currentImage == null) { currentImage = new Image(){ Width = 640, Height = 480 }; mirrorWindow.Content = currentImage; } RenderTargetBitmap bitmap = new RenderTargetBitmap( (int)canvas.Width, (int)canvas.Height, 96d, 96d, PixelFormats.Pbgra32 ); bitmap.Render( canvas ); BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add( BitmapFrame.Create( bitmap ) ); BitmapImage bmp = new BitmapImage() { CacheOption = BitmapCacheOption.OnLoad }; MemoryStream outStream = new MemoryStream(); encoder.Save(outStream); outStream.Seek(0, SeekOrigin.Begin); bmp.BeginInit(); bmp.StreamSource = outStream; bmp.EndInit(); currentImage.Source = bmp; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload