I am trying to print a WPF UserControl that I am creating in code. I do this using the DocumentPaginator implementation at the end of the post.
The problem is that the DocumentPage class does not call Loaded on my UserControl, so the control does not fully render. I cannot move the code in OnLoaded to a better place, because I am not a control keeper.
What is the correct way to fire the Loaded event on a control? I understand that an event is fired only when the control is connected to the PresentationSource, but I'm trying to send a print job by showing the contents on the screen. I could probably display the control using Visibility = Hidden somewhere, but it looks cheap and hacked.
class MyPaginator : DocumentPaginator
{
public MyPaginator()
{
PageSize = new Size(800, 600);
}
public override DocumentPage GetPage(int pageNumber)
{
var uc = new ChartUC();
uc.Measure(PageSize);
uc.Arrange(new Rect(PageSize));
uc.UpdateLayout();
return new DocumentPage(uc, PageSize, new Rect(PageSize), new Rect(PageSize));
}
public override bool IsPageCountValid
{
get { return true; }
}
public override int PageCount
{
get { return 1; }
}
public override System.Windows.Size PageSize
{
get;
set;
}
public override IDocumentPaginatorSource Source
{
get { return null; }
}
}
source
share