Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The data in your chart is not rendered in your PNG file because there is an animation applied to the reveal of the data points. Take a look at your LetterFrequency control in a Window, and you'll see the points gradually reveal themselves.</p> <p>Your code takes a snapshot of the control immediately after its creation, so you see no data.</p> <p>You could:</p> <ol> <li>wrap all this in a window and tell it to take the snapshot after X seconds </li> <li>disable all the animations in any controls you're going to snapshot </li> <li>maybe there's a way to "fast-forward" animations programmatically, but i couldn't find one</li> </ol> <p>Here's solution 1, and it works:</p> <pre><code> public partial class Window1 : Window { System.Windows.Threading.DispatcherTimer snapshotTimer; public Window1() { InitializeComponent(); this.Width = 600; this.Height = 400; let.Width = 600; let.Height = 400; let.Background = Brushes.White; this.Loaded += new RoutedEventHandler(Window1_Loaded); } void Window1_Loaded(object sender, RoutedEventArgs e) { this.snapshotTimer = new System.Windows.Threading.DispatcherTimer(); this.snapshotTimer.Interval = TimeSpan.FromSeconds(2); this.snapshotTimer.Tick += new EventHandler(snapshotTimer_Tick); this.snapshotTimer.IsEnabled = true; } void snapshotTimer_Tick(object sender, EventArgs e) { this.snapshotTimer.IsEnabled = false; WritePng(); } void WritePng() { RenderTargetBitmap bitmap = new RenderTargetBitmap((int)let.Width, (int)let.Height, 96d, 96d, PixelFormats.Pbgra32); bitmap.Render(let); PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(BitmapFrame.Create(bitmap)); using (Stream stm = File.Create("test.png")) { png.Save(stm); } this.Close(); } } </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