[英]RIchTextBox Rtf encoding
I created a richtextbox in wpf where i can select text and link it to a file or resource.我在 wpf 中创建了一个富文本框,我可以在其中 select 文本并将其链接到文件或资源。 Let's say i want to add text something into textbox and add hyperlink to D:\cdrréper假设我想在文本框中添加一些文本并将超链接添加到D:\cdrréper
I attach a part of the code:我附上部分代码:
_link.CommandParameter = path;
_link.NavigateUri = new Uri(path, UriKind.Absolute);
_link.IsEnabled = true;
using (MemoryStream ms = new MemoryStream()) {
TextRange tr = new TextRange(_link.ContentStart, _link.ContentEnd);
tr.Save(ms, DataFormats.Rtf);
richTextBox.Selection.Load(ms, DataFormats.Rtf);
}
The current text value in richtext box after load is加载后富文本框中的当前文本值为
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Arial;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red0\green102\blue204;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\ul\cf3\ltrch {\field{\*\fldinst { HYPERLINK "D:\\\\cdrr'e9per" }}{\fldrslt {something}}}}\li0\ri0\sa75\sb75\fi0\ql\par}
}
}
Hyperlink value from RTF is { HYPERLINK "D:\\cdrr'e9per" } . RTF 中的超链接值为{ HYPERLINK "D:\\cdrr'e9per" } 。 When i'm trying to access the path is not working because cannot be founded.当我尝试访问路径时,由于无法建立,该路径无法正常工作。 é character is not encoded correctly. é字符编码不正确。 Do you have any suggestions about how i can fix this?你对我如何解决这个问题有什么建议吗? Thanks for any help.谢谢你的帮助。
In the Hyperlink section is needed to have a \ before 'e9.在超链接部分需要在 'e9. When we load the rtf string into a TextRange we need to Load it as Xaml.当我们将 rtf 字符串加载到 TextRange 时,我们需要将其加载为 Xaml。
tr.Load(ms, DataFormats.Xaml);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.