I have a windows service that periodically sends emails with images of ChartView controls. I am having a hard time getting the ChartView to fully render unless I attach it to a window and show the window and then immediately close it. The code is running from a windows service and so this is really not desired.
If I render the control using the following BuildContentStream method then it simply displays the "No data to display message"
private
MemoryStream BuildContentStream(FrameworkElement visualItem,
int
width,
int
height)
{
var view = visualItem;
view.Measure(
new
Size(width, height));
view.Arrange(
new
Rect(0, 0, width, height));
view.UpdateLayout();
var rtb =
new
RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
rtb.Render(view);
var png =
new
PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
var memStream =
new
MemoryStream();
png.Save(memStream);
memStream.Position = 0;
return
memStream;
}
If I attach the control to a window and then do the following then it works correctly.
// The window acts as a visualizer. Can't get it working otherwise
var window =
new
RadWindow();
window.Height = 300;
window.Width = 400;
window.Content = errorItem.View;
window.WindowState = WindowState.Normal;
window.Show();
window.Close();
var stream = BuildContentStream(errorItem.View, 400, 300);
I have also tried the ExportToImage extension without success?
Is it possible to get this working from a windows service without any UI?