title: Convert XAML to FlowDocument to display in RichTextBox in WPF
body: <p>I have some HTML, which i am converting to XAML using the library provided by Microsoft </p>
  
  <pre><code>string t = HtmlToXamlConverter.ConvertHtmlToXaml(mail.HtmlDataString,true);
  </code></pre>
  
  <p>now, from  <a href="https://stackoverflow.com/questions/1449121/how-to-insert-xaml-into-richtextbox">How to insert XAML into RichTextBox?</a> i am using the following:</p>
  
  <pre><code>private static FlowDocument SetRTF(string xamlString)
  {
      StringReader stringReader = new StringReader(xamlString);
      System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);
      Section sec = XamlReader.Load(xmlReader) as Section;
      FlowDocument doc = new FlowDocument();
      while (sec.Blocks.Count &gt; 0)
          doc.Blocks.Add(sec.Blocks.FirstBlock);
      return doc;
  }
  </code></pre>
  
  <p>This however keeps crashing unfortunately =/ Does anyone have any clue on how to display XAML text in a RichTextBox please?</p>
  
  <p>EDIT: Example of html i'm trying to convert</p>
  
  <pre><code>&lt;FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Paragraph&gt;Top stories for&lt;LineBreak /&gt;Tuesday,&lt;LineBreak /&gt;May 4, 2010&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Paragraph&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://adverts.timesofmalta.com/openx/www/delivery/ck.php?zoneid=7" /&gt;&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"&gt;&lt;Paragraph FontSize="17px"&gt;Latest News&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Paragraph&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local"&gt;News&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/code-breaker"&gt;Code breaker&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/persuni-li-spiccaw-il-habs-minhabba-kazijiet-ta-vat"&gt;106 in prison since 2004 for VAT violations&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/mumn-disappointed-over-deployment-of-nurses"&gt;MUMN disappointed over deployment of nurses&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/press-digest"&gt;Press digest&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news"&gt;World News&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/new-iceland-volcano-ash-grounds-flights-in-ireland"&gt;Ash cloud returns: Ryanair cancels Malta flight from Dublin&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/man-arrested-over-ny-bomb-attempt-reports"&gt;Man arrested over NY bomb attempt: reports&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Table&gt;&lt;TableRowGroup&gt;&lt;TableRow&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"&gt;&lt;Paragraph FontSize="17px"&gt;The Times&lt;LineBreak /&gt;&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;TableCell BorderThickness="1,1,1,1" BorderBrush="Black"&gt;&lt;Paragraph&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local"&gt;News&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/injured-president-returns-from-china"&gt;Injured President returns from China&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/law-breakers-to-be-barred-from-public-contracts"&gt;VAT fraud - Law breakers to be barred from public contracts&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/warden-assaulted-on-parking-ticket"&gt;Warden 'assaulted' on parking ticket&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/against-the-law"&gt;Against the law?&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/linkin-park-the-kooks-for-isle-of-mtv-concert"&gt;Linkin Park, The Kooks for Isle of MTV concert&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news"&gt;World News&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/mumbai-attacks-gunman-convicted"&gt;Mumbai attacks gunman convicted&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/ireland-britain-eye-new-ash-flight-bans"&gt;Ireland, Britain eye new ash flight bans&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/white-male-suspect-linked-to-times-square-car-bomb"&gt;White male suspect linked to Times Square car bomb&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/iranian-president-blasts-us-for-nuclear-threats"&gt;Iranian President blasts US for nuclear threats&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/strikes-to-disrupt-greek-flights-as-from-today"&gt;Strikes to disrupt Greek flights as from today&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/business"&gt;Business &amp;amp; Finance&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/ecb-returns-to-variable-rate-tender-procedures"&gt;Money market report - week ended April 30 - ECB returns to variable rate tender procedures&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/new-chairman-for-volksbank-malta-ltd"&gt;New chairman for Volksbank Malta Ltd&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/daily-currency-report"&gt;Daily currency report&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/financial-news"&gt;Financial news&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/european-stocks-shake-off-early-jitters-and-gain-ground"&gt;Market overview - European stocks shake off early jitters and gain ground&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/sport"&gt;Sport&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/valletta-part-with-obrien"&gt;Football - Valletta part with O'Brien&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/title-clinching-goal-just-reward-for-ebullient-bajada"&gt;Football - BOV Premier League - Title-clinching goal just reward for ebullient Bajada&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/draw-enough-for-sliema-to-secure-third-place"&gt;Football - BOV Premier League - Draw enough for Sliema to secure third place&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/bov-premier-league-highlights"&gt;Football - BOV Premier League highlights&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/mqabba-finish-on-a-high"&gt;Football - Mqabba finish on a high&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/opinion"&gt;Opinion&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/editorial"&gt;Editorial - Keeping to the right financial track&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/habitats-of-the-maltese-islands-7"&gt;One World - Habitats of the Maltese islands (7)&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/guaranteeing-our-heritages-future"&gt;Guaranteeing our heritage's future&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/mixed-data-on-environment"&gt;Mixed data on environment&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/an-issue-of-accountability"&gt;An issue of accountability&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;Span FontWeight="bold"&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/letters"&gt;Letters&lt;/Hyperlink&gt;&lt;/Span&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/service-deserving-of-a-national-award"&gt;Service deserving of a national award&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/vulgar-perception-of-latin-language"&gt;Vulgar perception of Latin language&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/chemical-spray-used-on-potato-crops"&gt;Chemical spray used on potato crops&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-1"&gt;Blasted from the past (1)&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-2"&gt;Blasted from the past (2)&lt;/Hyperlink&gt;&lt;LineBreak /&gt;&lt;LineBreak /&gt;&lt;/Paragraph&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/TableCell&gt;&lt;/TableRow&gt;&lt;/TableRowGroup&gt;&lt;/Table&gt;&lt;/FlowDocument&gt;
  </code></pre>