English 中文(简体)
我如何将案文转换成WPFRichTextBox流程文件中的超链接?
原标题:How do I convert text to hyperlink in a WPF RichTextBox FlowDocument?

我试图将一些案文转向超链接,而用户正在WPFRichTextBox打字。

我第一次尝试是在每一个关键人物执行这一守则:

Regex r = new Regex("[A-Z]{3}");
FlowDocument doc = this.inputBox.Document;            
String text = new TextRange(doc.ContentStart, doc.ContentEnd).Text;

foreach (Match m in r.Matches(text))
{
    TextPointer start = doc.ContentStart.GetPositionAtOffset(m.Index + 2);                
    TextPointer end = doc.ContentStart.GetPositionAtOffset(m.Index + m.Length + 2);
    Hyperlink sp = new Hyperlink(start, end);
}

用户首次填写了3份资本信(ABC)的顺序,但超文本链接的制作在进入第二序列时却无例外。 在清点时看变量,看来两个文本点都在第一顺序。

问题回答

我认为,你的问题可能是由于对“GetPositionAtOffset()”方法的共同误解。

GetPositionAtOffset 返回,在《流动文件》中填注<>,而不是<>可见文本抵消

在您插入第一个超级链接后,流程文件载有开端和结关:

<Hyperlink>the_regex_match</Hyperlink>

这意味着,流动文件不再与RegEx配对机返回的平原文字特征指数一致。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签