views:

617

answers:

3

Has anyone found a way to save a FlowDocument as BAML or other compressed format? I can import XML with images to create a new FlowDocument:

<TextRange class instance>.Load(fs, DataFormats.Rtf)

However, I haven't found a good way to save it in a 'native' compressed format. Uncompressed XAML is easy to generate using:

<TextRange class instance>.Save(fs, DataFormats.Xaml);

But is there any programmatic method to save it to a compressed format?

If there isn't an existing method, does anyone know where to find a programmatic XAML compiler? Or even just the BAML specifications? I could programmatically generate an entire XAML window with the FlowDocument embedded, but I'd still want to convert the XAML to BAML for faster load times. I'm using relatively large rtf documents and conversion time using DataFormats.Rtf is significant.

+1  A: 

I do not think it is possible... The BamlWriter is marked as internal, this will hopefully open up soon!

I unfortunatly do not know of any XAML compilers

rudigrobler
A: 

Well, it turns out you can run Visual C# 2008 Express w/o the GUI. And you can modify the final program name via code before you compile as well. I'm sure you can do it via APIs, but here's the hack I found:

  1. The program's is name determined in .csproj, in the xml tag.
  2. Run via code or batch file: "\Common7\IDE\vcsexpress" ".sln" /rebuild Release /projectconfig Release /out errors.txt

I like to examine and then delete the errors.txt after each run to make it easier to see if I got a clean build. This isn't ideal because you have to have a full bought version of Visual C# 2008 on each machine you use this way, but it is a way to create a new executable to display each flow document in a programatic way. Also if you have an error in your XAML, you may generate a program that won't run.

Note that the BAML format does NOT compress the text, only the tags and other 'plumbing'. Even the Margin and Padding information is saved in clear ASCII. This is inherited by the end .exe leaving the text clearly visible in sections to notepad or similar.

Fred
A: 

The XamlPackage format is compressed:

<TextRange class instance>.Save(fs, DataFormats.Xaml);
Fred