将 XAML 转换为 FlowDocument 以在 WPF 中的 RichTextBox 中显示
我有一些 HTML,我现在使用 Microsoft 提供的库将其转换为 XAML
string t = HtmlToXamlConverter.ConvertHtmlToXaml(mail.HtmlDataString,true);
,来自 如何将 XAML 插入 RichTextBox? 我正在使用以下内容:
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 > 0)
doc.Blocks.Add(sec.Blocks.FirstBlock);
return doc;
}
不幸的是,这一直崩溃 =/ 有人知道如何在 RichTextBox 中显示 XAML 文本吗?
编辑:我正在尝试转换的 html 示例
<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph>Top stories for<LineBreak />Tuesday,<LineBreak />May 4, 2010</Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><Hyperlink Foreground="#555555" NavigateUri="http://adverts.timesofmalta.com/openx/www/delivery/ck.php?zoneid=7" /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"><Paragraph FontSize="17px">Latest News</Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local">News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/code-breaker">Code breaker</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/persuni-li-spiccaw-il-habs-minhabba-kazijiet-ta-vat">106 in prison since 2004 for VAT violations</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/mumn-disappointed-over-deployment-of-nurses">MUMN disappointed over deployment of nurses</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/press-digest">Press digest</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news">World News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/new-iceland-volcano-ash-grounds-flights-in-ireland">Ash cloud returns: Ryanair cancels Malta flight from Dublin</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/man-arrested-over-ny-bomb-attempt-reports">Man arrested over NY bomb attempt: reports</Hyperlink><LineBreak /><LineBreak /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"><Paragraph FontSize="17px">The Times<LineBreak /></Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local">News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/injured-president-returns-from-china">Injured President returns from China</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/law-breakers-to-be-barred-from-public-contracts">VAT fraud - Law breakers to be barred from public contracts</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/warden-assaulted-on-parking-ticket">Warden 'assaulted' on parking ticket</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/against-the-law">Against the law?</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/linkin-park-the-kooks-for-isle-of-mtv-concert">Linkin Park, The Kooks for Isle of MTV concert</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news">World News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/mumbai-attacks-gunman-convicted">Mumbai attacks gunman convicted</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/ireland-britain-eye-new-ash-flight-bans">Ireland, Britain eye new ash flight bans</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/white-male-suspect-linked-to-times-square-car-bomb">White male suspect linked to Times Square car bomb</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/iranian-president-blasts-us-for-nuclear-threats">Iranian President blasts US for nuclear threats</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/strikes-to-disrupt-greek-flights-as-from-today">Strikes to disrupt Greek flights as from today</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/business">Business & Finance</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/ecb-returns-to-variable-rate-tender-procedures">Money market report - week ended April 30 - ECB returns to variable rate tender procedures</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/new-chairman-for-volksbank-malta-ltd">New chairman for Volksbank Malta Ltd</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/daily-currency-report">Daily currency report</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/financial-news">Financial news</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/european-stocks-shake-off-early-jitters-and-gain-ground">Market overview - European stocks shake off early jitters and gain ground</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/sport">Sport</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/valletta-part-with-obrien">Football - Valletta part with O'Brien</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/title-clinching-goal-just-reward-for-ebullient-bajada">Football - BOV Premier League - Title-clinching goal just reward for ebullient Bajada</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/draw-enough-for-sliema-to-secure-third-place">Football - BOV Premier League - Draw enough for Sliema to secure third place</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/bov-premier-league-highlights">Football - BOV Premier League highlights</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/mqabba-finish-on-a-high">Football - Mqabba finish on a high</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/opinion">Opinion</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/editorial">Editorial - Keeping to the right financial track</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/habitats-of-the-maltese-islands-7">One World - Habitats of the Maltese islands (7)</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/guaranteeing-our-heritages-future">Guaranteeing our heritage's future</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/mixed-data-on-environment">Mixed data on environment</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/an-issue-of-accountability">An issue of accountability</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/letters">Letters</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/service-deserving-of-a-national-award">Service deserving of a national award</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/vulgar-perception-of-latin-language">Vulgar perception of Latin language</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/chemical-spray-used-on-potato-crops">Chemical spray used on potato crops</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-1">Blasted from the past (1)</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-2">Blasted from the past (2)</Hyperlink><LineBreak /><LineBreak /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></FlowDocument>
I have some HTML, which i am converting to XAML using the library provided by Microsoft
string t = HtmlToXamlConverter.ConvertHtmlToXaml(mail.HtmlDataString,true);
now, from How to insert XAML into RichTextBox? i am using the following:
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 > 0)
doc.Blocks.Add(sec.Blocks.FirstBlock);
return doc;
}
This however keeps crashing unfortunately =/ Does anyone have any clue on how to display XAML text in a RichTextBox please?
EDIT: Example of html i'm trying to convert
<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph>Top stories for<LineBreak />Tuesday,<LineBreak />May 4, 2010</Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><Hyperlink Foreground="#555555" NavigateUri="http://adverts.timesofmalta.com/openx/www/delivery/ck.php?zoneid=7" /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"><Paragraph FontSize="17px">Latest News</Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local">News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/code-breaker">Code breaker</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/persuni-li-spiccaw-il-habs-minhabba-kazijiet-ta-vat">106 in prison since 2004 for VAT violations</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/mumn-disappointed-over-deployment-of-nurses">MUMN disappointed over deployment of nurses</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/press-digest">Press digest</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news">World News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/new-iceland-volcano-ash-grounds-flights-in-ireland">Ash cloud returns: Ryanair cancels Malta flight from Dublin</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/man-arrested-over-ny-bomb-attempt-reports">Man arrested over NY bomb attempt: reports</Hyperlink><LineBreak /><LineBreak /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Table><TableRowGroup><TableRow><TableCell BorderThickness="1,1,1,1" BorderBrush="Black" RowSpan="10"><Paragraph FontSize="17px">The Times<LineBreak /></Paragraph></TableCell><TableCell BorderThickness="1,1,1,1" BorderBrush="Black"><Paragraph><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/local">News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/injured-president-returns-from-china">Injured President returns from China</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/law-breakers-to-be-barred-from-public-contracts">VAT fraud - Law breakers to be barred from public contracts</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/warden-assaulted-on-parking-ticket">Warden 'assaulted' on parking ticket</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/against-the-law">Against the law?</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/local/linkin-park-the-kooks-for-isle-of-mtv-concert">Linkin Park, The Kooks for Isle of MTV concert</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/world-news">World News</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/mumbai-attacks-gunman-convicted">Mumbai attacks gunman convicted</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/ireland-britain-eye-new-ash-flight-bans">Ireland, Britain eye new ash flight bans</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/white-male-suspect-linked-to-times-square-car-bomb">White male suspect linked to Times Square car bomb</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/iranian-president-blasts-us-for-nuclear-threats">Iranian President blasts US for nuclear threats</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/world-news/strikes-to-disrupt-greek-flights-as-from-today">Strikes to disrupt Greek flights as from today</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/business">Business & Finance</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/ecb-returns-to-variable-rate-tender-procedures">Money market report - week ended April 30 - ECB returns to variable rate tender procedures</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/new-chairman-for-volksbank-malta-ltd">New chairman for Volksbank Malta Ltd</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/daily-currency-report">Daily currency report</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/financial-news">Financial news</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/business/european-stocks-shake-off-early-jitters-and-gain-ground">Market overview - European stocks shake off early jitters and gain ground</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/sport">Sport</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/valletta-part-with-obrien">Football - Valletta part with O'Brien</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/title-clinching-goal-just-reward-for-ebullient-bajada">Football - BOV Premier League - Title-clinching goal just reward for ebullient Bajada</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/draw-enough-for-sliema-to-secure-third-place">Football - BOV Premier League - Draw enough for Sliema to secure third place</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/bov-premier-league-highlights">Football - BOV Premier League highlights</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/sport/mqabba-finish-on-a-high">Football - Mqabba finish on a high</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/opinion">Opinion</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/editorial">Editorial - Keeping to the right financial track</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/habitats-of-the-maltese-islands-7">One World - Habitats of the Maltese islands (7)</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/guaranteeing-our-heritages-future">Guaranteeing our heritage's future</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/mixed-data-on-environment">Mixed data on environment</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/opinion/an-issue-of-accountability">An issue of accountability</Hyperlink><LineBreak /><LineBreak /><Span FontWeight="bold"><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/headlines/20100504/letters">Letters</Hyperlink></Span><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/service-deserving-of-a-national-award">Service deserving of a national award</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/vulgar-perception-of-latin-language">Vulgar perception of Latin language</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/chemical-spray-used-on-potato-crops">Chemical spray used on potato crops</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-1">Blasted from the past (1)</Hyperlink><LineBreak /><Hyperlink Foreground="#555555" NavigateUri="http://www.timesofmalta.com/articles/view/20100504/letters/blasted-from-the-past-2">Blasted from the past (2)</Hyperlink><LineBreak /><LineBreak /></Paragraph></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></TableCell></TableRow></TableRowGroup></Table></FlowDocument>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设它在
Add()
上崩溃,因为您添加的FrameworkContentElement
已经有一个逻辑父级。您必须首先从其父级中删除Block
,然后才将其添加到不同的集合中。试试这个:如果您的 XAML 已经代表 FlowDocument
那么事情就简单得多。只需执行以下操作:
用法
richTextBox.Document = SetRTF(xamlString);
I assume it crashes on
Add()
because you are adding aFrameworkContentElement
which already has a logical parent. You must first remove aBlock
from its parent and only then add it to a different collection. Try this:If your XAML already represents a FlowDocument
Then things are much simpler. Just do a:
Usage
richTextBox.Document = SetRTF(xamlString);
或短
or short