I Have a WindowsService project.In this service when I render any UserControl, the png file is empty.
for test i write the following code to export a TextBlock but result is an empty png file.
protected override void OnCustomCommand(int command)
{
Export();
base.OnCustomCommand(command);
}
private void Export()
{
var thread = new Thread(() =>
{
var grid = new Grid();
grid.Children.Add(new TextBlock() { Text = "ExportTest", FontSize = 60, Background = Brushes.Red, Foreground = Brushes.Blue });
double widthg = grid.Width > 0 ? grid.Width : 1024;
double heightg = grid.Height > 0 ? grid.Height : 768;
grid.Measure(Size.Empty);
grid.Measure(new Size(widthg, heightg));
grid.Arrange(new Rect(0, 0, widthg, heightg));
grid.UpdateLayout();
var bitmap = new PngBitmapEncoder();
ExportExtensions.ExportToImage(grid, @"..\ExportTest.png", bitmap);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
Note: when I run the export function in wpf project, it works perfect.
there is my project:
http://www.mediafire.com/file/aij5sg4zx80yc73/ExportProject.rar
any body can help me?
for test i write the following code to export a TextBlock but result is an empty png file.
protected override void OnCustomCommand(int command)
{
Export();
base.OnCustomCommand(command);
}
private void Export()
{
var thread = new Thread(() =>
{
var grid = new Grid();
grid.Children.Add(new TextBlock() { Text = "ExportTest", FontSize = 60, Background = Brushes.Red, Foreground = Brushes.Blue });
double widthg = grid.Width > 0 ? grid.Width : 1024;
double heightg = grid.Height > 0 ? grid.Height : 768;
grid.Measure(Size.Empty);
grid.Measure(new Size(widthg, heightg));
grid.Arrange(new Rect(0, 0, widthg, heightg));
grid.UpdateLayout();
var bitmap = new PngBitmapEncoder();
ExportExtensions.ExportToImage(grid, @"..\ExportTest.png", bitmap);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
Note: when I run the export function in wpf project, it works perfect.
there is my project:
http://www.mediafire.com/file/aij5sg4zx80yc73/ExportProject.rar
any body can help me?