次のように、FixedDocumentをさらに多くの反復(反復ごとに1ページ)で作成します。
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");
各反復で、MainGridを少し変更します。したがって、各ページにはMainGridの実際の状態が含まれている必要があります。ただし、印刷されたドキュメントには、最後の反復と同じ内容のページが含まれています(つまり、最後の状態はドキュメント内のすべてのページにあります)。VisualBrushなどの「遅延評価」はありますか?