Click here to Skip to main content
15,743,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 and when I press space or enter key after "m" in "" 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[^]

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

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)

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... :)
Share this answer
Tarun.K.S 15-Jul-11 13:46pm    
Nice link. Bookmarked for future reference! 5+
I think you just need to make sure that the detecturl property of the richtextbox is set to true.

Look at the following link[^]

Hope this is helpful.

Share this answer
Tarun.K.S 15-Jul-11 13:45pm    
Nice link. 5+
ankitjoshi24 15-Jul-11 14:01pm    
thank you :-)
deveoper12345 18-Jul-11 5:26am    
Hi thanks but it is windows control property not of wpf richtextbox

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900