反序列化整个FlowDocument问题

时间:2012-09-11 11:45:19

标签: c# .net wpf

我有以下字符串

<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>Some text <LineBreak /><LineBreak /> <Run FontWeight="bold">Text ...</Run><LineBreak />sjhfdjsgfjsd <LineBreak /><LineBreak /> <Run FontWeight="bold">Text 2 </Run><LineBreak />sdkfskfjsf <LineBreak /><LineBreak /> </Paragraph></FlowDocument>

我尝试使用此代码将其反序列化为FlowDocument,但没有成功。

任何线索我错过了什么?

谢谢!

CODE

 StringReader stringReader = new StringReader(xamlString);
 XmlReader xmlReader = XmlReader.Create(stringReader);
 Section sec = XamlReader.Load(xmlReader) as Section;
 FlowDocument doc = new FlowDocument();
 while (sec.Blocks.Count > 0)
   doc.Blocks.Add(sec.Blocks.FirstBlock);
 return doc;

1 个答案:

答案 0 :(得分:0)

好的。我找到了。

 var stringReader = new StringReader(xamlString);
 var xmlReader = XmlReader.Create(stringReader);
 var doc= XamlReader.Load(xmlReader) as FlowDocument;