wpf - Writing out FlowDocument xaml with namespace using XmlWriter -


i've got collection of data needs converted .xaml file can later loaded flowdocument flowdocumentreader. don't directly instantiate paragraphs, runs, rather generate xaml create document later.

what i've tried:

i iterate through data, creating xelements paragraphs, runs, inlineuicontainers, etc. , build flowdocument structure fine , call:

xmlwriter writer = xmlwriter.create("output.xaml"); flowdocelem.writeto(writer); writer.close(); 

in consuming app, this:

flowdocument = xamlreader.load(xamlfile) flowdocument; flowdocumentreader.document = flowdocument; xamlfile.close(); 

but loading fails because doesn't know flowdocument is. flowdocument element looks so:

<flowdocument name="testdoc"> 

(there's no namespace there shed light flowdocument when read in.)

if hand edit .xaml , modify element be:

<flowdocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" name="testdoc">

then it'll load fine.

when creating xelement flowdocument, i've tried this:

new xelement("flowdocument", new xattribute("name", "testdoc"), new xattribute("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation")); 

but doesn't work either - gives me error if try create namespace attribute.

i can cheat , stuff xmlns element , call like

file.writealltext("output.xaml", fixedtxt); 

but feels dirty , think i'm plain doing wrong.

thoughts?


update:

while isn't prescriptive solution problem, does work:

by adding parsercontext xamlreader, able past problem loading flowdocument xml.

filestream xamlfile = new filestream("output.xaml", filemode.open, fileaccess.read); xamlreader x = new xamlreader(); parsercontext parsercontext = new parsercontext(); parsercontext.xmlnsdictionary.add("","http://schemas.microsoft.com/winfx/2006/xaml/presentation"); flowdocument = xamlreader.load(xamlfile, parsercontext) flowdocument; flowdocumentreader.document = flowdocument; xamlfile.close(); 

try using xamlwriter instead of xmlwriter.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -