Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to render Chart (from wpf toolkit) control offscreen?
    text
    copied!<p>I want to render a Chart control (from WPF toolkit <a href="http://wpf.codeplex.com" rel="nofollow">http://wpf.codeplex.com</a>) in console application (I acutally never show it to the user), but I keep on getting an empty image. If I pick some other control (e.g. TextBlock) then everything works as expected. Here is the code to reproduce the problem:</p> <p>// BEGIN</p> <p><code>Chart chart = new Chart { Width = 300, Height = 230 };</code><br> // I do not add series yet, because I thought that maybe that caused problems...<br> <code>chart.Background = Brushes.Blue;</code><br> <code>chart.BorderBrush = Brushes.Red;</code><br> <code>chart.BorderThickness = new Thickness(10);</code><br> <code>chart.Title = "Test chart";</code><br> <code>chart.Measure(new Size(chart.Width, chart.Height));</code><br> <code>chart.Arrange(new Rect(new Size(chart.Width, chart.Height)));</code> </p> <p><code>RenderTargetBitmap rtb = new RenderTargetBitmap((int)chart.Width, (int)chart.Height, 96, 96, PixelFormats.Pbgra32);</code><br> <code>rtb.Render(chart);</code><br> <code>PngBitmapEncoder png = new PngBitmapEncoder();</code><br> <code>png.Frames.Add(BitmapFrame.Create(rtb));</code><br> <code>using (System.IO.Stream stream = System.IO.File.Create("C:\\chart.png"))</code><br> <code>{</code><br> <code>png.Save(stream);</code><br> <code>}</code> </p> <p>// END</p> <p>If I run this code in not Console but WPF application, where chart is a control shown on the form, everything works fine. People mention something about the animations used to draw the control on different thread. I tried putting my main thread asleep, hoping that the other then will have time to draw the graph. No luck here either...</p> <p>Anyone ideas? How can I render this control offscreen?</p>
 

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