WPF RichText框检测超链接 [英] wpf richtext box detect hyperlink

查看:80
本文介绍了WPF RichText框检测超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我开始研究WPF richtextbox,似乎它没有像Windows richtextbox中那样具有自动检测url的功能.当我们将数据粘贴到richtextbox(wpf)中时,我需要帮助检测超链接. "www.google.com"将返回并检查前一个空格,或输入并检测超链接并使之成为超链接.

我使用以下代码处理
http://social.msdn.microsoft.com/论坛/en-US/wpf/thread/d3b82728-2b16-4b53-9550-e1cc5c39b169 [
GetPositionAtOffset(match.index,LogicalDirection.Forward)

并指出要点
但出现以下错误:

1)超链接不能存在于其他的边界中(可以被捕获块捕获,所以没什么大问题)

当我们在其中粘贴文本时,有人可以帮助我检测网址吗?




2)错误代码0x80131623(在Google上可以找到详细信息),对我来说真的很麻烦.


(对于语法或英语错误,我深表歉意)
谢谢

Hi all I started working on WPF richtextbox and it seems that it does not have features like auto detect url as in windows richtextbox. I need help in detecting hyperlink when we paste data in the richtextbox (wpf) .I already found some code blocks which works fine with typed words like I type www.google.com and when I press space or enter key after "m" in "www.google.com" it will traverse back and check for the previous space or enter and detect hyperlink and make it hyperlink.

I used following code to work with
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d3b82728-2b16-4b53-9550-e1cc5c39b169[^]

It works fine most of the time but my problem is it goes to the link after traversing every character and when I have a lot of data it is not a better solution. Also it does not work with multiple paragraphs.

I tried another option to jump directly to the link word and detect it and make it hyperlink using following function

here match is a match collection which contains all the matches of urls
here I used following regex value
"(?<=\w{1})?(((ht|f)tp(s?))\://)?(www.[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\''\\\+&amp;%\$#\=~_\-]+))*"

GetPositionAtOffset(match.index, LogicalDirection.Forward)

and get the point
But I get the following errors :

1) Hyperlink can not exists in the boundry of other ( can be caught in catch block so not a big problem)

Can anyone please help me in detecting urls when we paste text in it.




2 )Error code 0x80131623 ( can be found details when googled) and really challanging for me.


( I really apologize for grammatical or English mistakes)
Thanks

推荐答案

| [a-zA-Z0-9 \.\,\; \?\?\''\\\ +&%\
|[a-zA-Z0-9\.\,\;\?\''\\\+&amp;%\


#\ =〜_ \-] +)))"

GetPositionAtOffset(match.index,LogicalDirection.Forward)

并指出要点
但出现以下错误:

1)超链接不能存在于其他的边界中(可以被捕获块捕获,所以没什么大问题)

当我们在其中粘贴文本时,有人可以帮助我检测网址吗?




2)错误代码0x80131623(在Google上可以找到详细信息),对我来说真的很麻烦.


(对于语法或英语错误,我深表歉意)
谢谢
#\=~_\-]+))*"

GetPositionAtOffset(match.index, LogicalDirection.Forward)

and get the point
But I get the following errors :

1) Hyperlink can not exists in the boundry of other ( can be caught in catch block so not a big problem)

Can anyone please help me in detecting urls when we paste text in it.




2 )Error code 0x80131623 ( can be found details when googled) and really challanging for me.


( I really apologize for grammatical or English mistakes)
Thanks


也许在这里有帮助...

在RichTextBox中自动检测超链接-第一部分 [在RichTextBox中自动检测超链接-第二部分 [
Maybe some help in here...

Auto-detecting Hyperlinks in RichTextBox - Part I[^]
Auto-detecting Hyperlinks in RichTextBox - Part II[^]


*Edit* Or maybe not...looks like you need regex help, not a way to detect URLs... :)


这篇关于WPF RichText框检测超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆