简体   繁体   English

在WPF RichTextBox中检测超链接

[英]Detecting hyperlinks in WPF RichTextBox

Hey folks, I'm wanting to write some rudimentary support for detecting hyperlinks in a WPF RichTextBox control. 大家好,我想写一些基本的支持来检测WPF RichTextBox控件中的超链接。 My plan is to use a regex to identify any links and then manually replace them with real hyperlink objects. 我的计划是使用正则表达式来标识任何链接,然后将其手动替换为真正的超链接对象。

However the part I am having trouble with is getting the correct textpointers, etc. once I find a link. 但是,一旦找到链接,我遇到的问题就是获取正确的文本指针等。 For example, I can flatten the entire document to a text string and find links, but once I do that how can I get the proper pointer to the block that needs url-ifying? 例如,我可以将整个文档展平为文本字符串并找到链接,但是一旦这样做,我如何才能找到需要URL修饰的正确指针?

Perhaps a better approach would be to iterate over blocks in the document, assuming a url would not span multiple blocks, however even then I have very little experience working with the RichTextBox/FlowDocument object model so any pointers (pun intended) would be helpful. 也许更好的方法是在一个URL不会跨越多个块的情况下遍历文档中的块,但是即使那样,我对RichTextBox / FlowDocument对象模型的使用也很少,因此任何指针(双关语都可以)会有所帮助。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM