Snapshots of Control in time using VisualBrush stored in one Fixed(Flow)Document

后端 未结 1 787
猫巷女王i
猫巷女王i 2021-01-14 02:28

I need to take snapshots of Control in time and store them in one FixedDocument. Problem is that VisualBrush is somehow \"lazy\" and do not evaluate itself by adding it to d

相关标签:
1条回答
  • 2021-01-14 03:17

    I used serialization:

    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

    Better way is to save Visual as XPS document and then take the Visual back. (De)serialization has some problems with SharedSizeGroups and many other "reference like" things.

    XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
    control.InvalidateArrange();
    UpdateLayout();
    writer.Write(control);
    Visual capture = doc.GetFixedDocumentSequence().DocumentPaginator.GetPage(0).Visual;
    
    0 讨论(0)
提交回复
热议问题