【问题标题】:VisualBrush does "lazy evaluation"?VisualBrush 做“懒惰评估”?
【发布时间】:2011-11-08 02:45:21
【问题描述】:

我在更多迭代中创建 FixedDocument(每次迭代一页),如下所示:

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之类的“懒评估”?

【问题讨论】:

    标签: wpf visualbrush fixeddocument


    【解决方案1】:

    在每次迭代中调用 VisualBrush 上的 .Freeze()。否则,它将始终是您指向的任何视觉对象的实时视图。

    编辑:冻结不起作用,但您可以将画笔渲染为静态位图。见http://blog.avanadeadvisor.com/blogs/markti/archive/2008/04/14/10888.aspx

    【讨论】:

    • 听起来不错,但 vb.CanFreeze 是错误的。但是您实际上确认它会进行某种惰性评估。谢谢
    • 我需要将它保存在向量中。所以我使用了序列化:link
    • @RobertLevy,您的链接已损坏,请修复或删除它。
    猜你喜欢
    • 2019-01-07
    • 2015-09-06
    • 2016-12-14
    • 2021-12-25
    • 2018-04-01
    • 2018-03-31
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多