WPF RichTextBox-导入的RTF文本无法正确呈现 [英] WPF RichTextBox - Imported RTF text not rendering properly
问题描述
我正在使用以下代码将RTF文本导入RichTextBox:
I am importing RTF text into a RichTextBox using the following code:
Using myStream As New MemoryStream(Encoding.UTF8.GetBytes(value))
Dim range As New TextRange(CurrentRichTextBox.Document.ContentStart, _
CurrentRichTextBox.Document.ContentEnd)
range.Load(myStream, DataFormats.Rtf)
End Using
加载后,文本会缩进显示.如果我使用表格RTF控件或将RTF正确加载到渲染器中.这是我要加载的RTF文本的示例:
When loaded the text appears indented. If I use the forms RTF control or Load the RTF in word in renders properly. Here is an example of RTF text that I'm trying to load:
{\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang4105 {\ fonttbl {\ f0 \ fnil \ fcharset0 Microsoft Sans Serif;}} \ viewkind4 \ uc1 \ pard \ fi-1420 \ li1420 \ f0 \ fs17 2000年1月1日, \ b法定名称更新\ par \ b0 S00000000将其法文名称更改为NEW 法律名称.\ par \ par \ pard \ par }
{\rtf1\ansi\ansicpg1252\deff0\deflang4105{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\fi-1420\li1420\f0\fs17 January 1, 2000\par \b Legal Name Update\par \b0 S00000000 changed its French legal name to for NEW LEGAL NAME.\par \par \pard\par }
有没有办法使它正确呈现?
Is there a way to get this to render properly?
为了澄清-上面仅是导致问题的RTF文本的示例.我一直在寻找的是是否可以更改代码示例以使其正确呈现.我发现奇怪的是其他工具(Forms,Word,Wordpad)正常工作,并且 WPF控件没有.我可能最终只包装表格控件,以将RTF-> Xaml-RTF转换排除在方程之外...
To clarify - the above is merely an example of RTF text causing the problem. What I was looking for was if the code sample could be changed to make it render properly. I find it strange that other tools (Forms, Word, Wordpad) work properly and the WPF control doesn't. I may end up just wrapping the forms control to take the RTF->Xaml-RTF convertion out of the equation...
谢谢.
推荐答案
我不是RTF格式的专家,但是当我更改代码以将字符串作为文本加载时,格式就可以了.我建议您尝试一次仅从RTF文本中添加部分,直到发现其中的代码导致 缩进.
I'm no expert on RTF formatting but when I change your code to just load a string in as text the formatting is fine. I would suggest that you try adding just sections at a time from your RTF text until you find the code within it that is causing the indent.
http://www.biblioscape.com/rtf15_spec.htm
http://www.biblioscape.com/rtf15_spec.htm
当我按下Enter键时,我会看到一个缩进代码.我删除了"\ li1420&"并且现在可以正确显示.
And as I hit enter I see an indent code. I removed the "\li1420" and it shows correctly now.
这篇关于WPF RichTextBox-导入的RTF文本无法正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!