c# - Convert a Flowdocument to XML and XML to Flowdocument -


i use code here(answer wiimax) convert flowdocument xml , convert flowdocument. have problems here.

my code convert:

public static bool isflowdocument(this string xamlstring)         {             if (xamlstring == null || xamlstring == "")                 throw new argumentnullexception();              if (xamlstring.startswith("<") && xamlstring.endswith(">"))             {                 xmldocument xml = new xmldocument();                 try                 {                     xml.loadxml(string.format("<root>{0}</root>", xamlstring));                     return true;                 }                 catch (xmlexception)                 {                     return false;                 }             }             return false;         }          public static flowdocument toflowdocument(this string xamlstring)         {             if (isflowdocument(xamlstring))             {                 var stringreader = new stringreader(xamlstring);                 var xmlreader = system.xml.xmlreader.create(stringreader);                  return xamlreader.load(xmlreader) flowdocument;             }             else             {                 paragraph myparagraph = new paragraph();                 myparagraph.inlines.add(new run(xamlstring));                 flowdocument myflowdocument = new flowdocument();                 myflowdocument.blocks.add(myparagraph);                  return myflowdocument;             }         } 

i enter code(as example, not code, use in program):

my code

and after convert code:

my code

you see blank skipped. , after namespace there add { } looked @ converted xml string, there no blank skipped, { } to

do know how fix or see fail me?

curly braces:

this because of binding-syntax , wpf (xamlreader , xamlwriter) wants ;).

when in xaml-code like

<run text="{" /> 

the xaml-engine first assumes binding. since there no , depending on how create flowdocument '{' escaped '{}{'

one workaround is, put curly brace this:

<run>{</run> 

another workaround avoid curly brace first character:

<run text=" {" /> 

spaces: there attribute comes in handy:

<run xml:space="preserve">some                   space</run> 

this isn't xaml xml attribute handled xaml-engine.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -