문제

I create FixedDocument in more iterations (one page per iteration) like this:

PrintDialog pr = new PrintDialog();
FixedDocument doc = new FixedDocument();

foreach(var i in a)
{
    // some changes of MaingGrid here
    ...
    //
    VisualBrush vb = new VisualBrush(this.MainGrid);
    FixedPage page = new FixedPage();
    page.Width = doc.DocumentPaginator.PageSize.Width;
    page.Height = doc.DocumentPaginator.PageSize.Height;
    Rectangle rec = new Rectangle();
    rec.Width = this.MainGrid.ActualWidth;
    rec.Height = this.MainGrid.ActualHeight;
    rec.Fill = vb;
    page.Children.Add(rec);
    PageContent content = new PageContent();
    ((IAddChild)content).AddChild(page);
    doc.Pages.Add(content);
}

pr.PrintDocument(doc.DocumentPaginator, "test");

In each iteration I change the MainGrid a little. So each page should contain the actual state of MainGrid. But the printed document contains pages with same content of last iteration (in other words - the last state is on all pages in document). Is there any "lazy evaluation" of VisualBrush or something?

도움이 되었습니까?

해결책

Call .Freeze() on the VisualBrush in each iteration. Otherwise, it will always be a live view of whatever visual you pointed it at.

EDIT: Freeze doesn't work but you can render the brush into a static bitmap. See http://blog.avanadeadvisor.com/blogs/markti/archive/2008/04/14/10888.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top