2

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?

karel
  • 1,297
  • 1
  • 10
  • 22

1 Answers1

0

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

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • Sounds good, but vb.CanFreeze is false. But you actualy confirm that it does some kind of lazy evaluation. Thank you – karel Nov 07 '11 at 15:14
  • I need to keep it in vectors. So I used serialization: [link](http://stackoverflow.com/questions/8039963/snapshots-of-control-in-time-using-visualbrush-stored-in-one-fixedflowdocument/8046947#8046947) – karel Nov 08 '11 at 07:01
  • @RobertLevy, your link is broken, please either fix it or remove it. – Sheridan Jan 31 '14 at 15:35