I'm attempting to render a XAML document using the chart series controls, but the visuals are not in the render result. Specifically, I have tried BarSeries and PieSeries, neither of which are rendered correctly.
To clarify, the underlying SfChart backdrop renders fine, it is only the foreground series control that does not work. Furthermore, if I add the same runtime-loaded page to a Window and display it, the chart renders fine, as expected.
To reproduce:
- Create a new WPF library (.NET 7)
- Set the output type to Exe (console application)
- Add the syncfusion chart library
- Create a XAML page with a SfChart control with a BarSeries chart (remove the class reference and underlying cs file, then set the file to copy to the output as Content)
- Create a top-level Program.cs and set the current thread
apartment state
to ApartmentState.Unknown and then ApartmentState.STA - Create a SfChart and discard it (to load the library)
- Load the XAML page with
- Cast the returned object to System.Windows.Controls.Page and call Arrange(Rect finalRect)
- Create a new RenderTargetBitmap instance with the XAML page with and height (DPI is best at 96, pixel format is PixelFormats.Pbgra32)
- Call RenderTargetBitmap.Render and pass in the loaded XAML page
- Use an image encoder to encode the bitmap and save it to a file
- See the result...
For better implementation details see the attached example project.