VisualBrush time-management snapshots stored in the same document with a fixed (stream)

I need to take Control snapshots in time and save them in one FixedDocument. The problem is that VisualBrush is somehow "lazy" and does not evaluate itself by adding it to the document. When I finally create the document, all pages contain the same (last) state of the control. Although VisualBrush cannot be frozen, is there any other chance? I would like to have more snapshots on one page, so creating a document page by page is not for me. Aswel as converting VisualBrush to Bitmap (I want to save it in vectors). In short - 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); } 
+4
source share
1 answer

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 fast :) svb = svb.Replace("Name", "Tag"); rect.Fill((VisualBrush)XamlReader.Parse(svb)); 

EDIT

It is best to save Visual as an XPS document and then return Visual. (De) serialization has some problems with SharedSizeGroups and many other "links like".

 XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); control.InvalidateArrange(); UpdateLayout(); writer.Write(control); Visual capture = doc.GetFixedDocumentSequence().DocumentPaginator.GetPage(0).Visual; 
+3
source

Source: https://habr.com/ru/post/1380029/


All Articles