我需要及时拍摄 Control 的快照并将它们存储在一个固定文档中。问题是 VisualBrush 在某种程度上是“懒惰的”,并且不会通过将其添加到文档来评估自身。当我最终创建文档时,所有页面都包含相同(最后)的控制状态。虽然 VisualBrush 无法被冻结,但还有其他机会可以做到这一点吗?我想在一页上有更多快照,因此逐页生成文档对我来说不是解决方案。以及将 VisualBrush 转换为位图(我想将其保留在矢量中)。简而言之 -I need to somehow Freeze() VisualBrush
for(;;)
{
FixedPage page = new FixedPage();
...
Rectangle rec = new Rectangle();
...
rec.Fill = vb;
page.Children.Add(rec);
PageContent content = new PageContent();
((IAddChild)content).AddChild(page);
doc.Pages.Add(content);
}
我使用序列化:
string svb = XamlWriter.Save(vb.CloneCurrentValue());
// Replace all "Name" attributes (I don't need them already and deserialization would crash on them) with "Tag" - not best practice but it's fast :)
svb = svb.Replace("Name", "Tag");
rect.Fill((VisualBrush)XamlReader.Parse(svb));
EDIT
更好的方法是将 Visual 保存为 XPS 文档,然后将 Visual 取回。 (反序列化对 SharedSizeGroup 和许多其他“类似引用”的东西存在一些问题。
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
control.InvalidateArrange();
UpdateLayout();
writer.Write(control);
Visual capture = doc.GetFixedDocumentSequence().DocumentPaginator.GetPage(0).Visual;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)