2012-09-11 55 views
0

我有以下字符串反序列化整個FlowDocument的問題

<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; 

回答

0

OK.I發現了它。

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