I've tried everything. I've found a blog post such as this one:
I've looked at other support tickets such as these:
It appears that no matter what I try, I can't get the XamDataChart to draw the lines that represent a series of data unless I first display the chart on the screen and the UI dispatcher thread suspends and user input is again active.
I am trying to export several XamDataChart controls to a PDF file using a third party PDF conversion library, but I've created a simple project to demonstrate my issue. This project displays two charts in one window. Then in code behind it creates another set of charts and copies a bitmap representation of them to the clipboard. The image will show the charts, but none of the traces show up. (Even after performing Measure(), Arrange(), UpdateLayout()) If I add the chart to the visual tree by adding them to a window that I display, and then re-render them, magically, all the lines show up again.
What is going on here? Am I doing something wrong? Why are the LineSeries that are created not shown until the charts are displayed on screen?
(Please note, this code was just thrown together and I realize that there is a bug with the X-Axis not displaying, that is not the issue I am concerned with)
The test program flows like this:
1. The main window is displayed with the first chart using lots of data binding. The second chart has it's lines defined and attached in code behind.
2. The user clicks the first button to render another instance of the control that contains the two charts in code behind (this simulates what I want to do to export the charts to a PDF). After the button is clicked, the control is rendered as a bitmap image and copied to the clipboard. (I created and saved the image in a photo editor)
3. The user clicks the second button. A new window is created and its content is set to be the control that was previously created in code-behind. The control is now displayed properly.
4. In step 3 a new image was rendered based off of the same control that was created in code behind. This rendered image is again copied to the clipboard. It magically shows the Lines that were created before now...
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
I was able to get the charts to render by calling the dispatcher to "delay" execution. However, I really wish there was a way to get everything to render without all these extra steps. Honestly, I'm most annoyed about having to manually call Measure and Arrange if the charts aren't displayed on screen. You'd think there'd be a way around this limitation. But I know that's a WPF issue.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well. Also I can say that I am not aware of a way to make this work, without calling Measure and Arrange methods, so you can ask your question in the MSDN forums, where you will get an answer from an MS expert.
I'm interested in this idea of rendering the chart, but instead of copying to clipboard I'd like to stream back the RenderTargetBitmap. I've tried modifying this code to work as such, but have been unsuccessful. Could you look into a way to send back the bitmap file?