How do I know if a TextRange is or contains a Hyperlink?
I tried with TextRange.GetPropertyValue(DependencyProperty), but I can't find de Dependency Property that identifies the specific range as hyperlink.
If not with 开发者_如何学PythonTextRange, is there anyway to find if a selected text inside a RichTextBox is a hyperlink?
Thanks :)
Found an answer that is not what I was looking for but still works very well.
Here is the answer. It's the GetHyperlinkAncestor Method. Hope it helps other people :)
The easiest way is to create a "try catch" and insert this code in the try. Hyperlink link = new Hyperlink();
link.NavigateUri = new Uri(link);
If you get an exception it isn't a valid hyperlink. You just have to handle the exception so that the program wan't die.
You can also do it manually by testing the string if it starts with "http://". This is done like this: `for(int i = 0; i
//Do something here
//And to chech the end of the link
if(link[link.lenght-1] == 'm' && link[link.lenght-2] == 'o' && link[link.length-3] == 'c'...
//Do something
}`
I hope you can use this. If not there is stil some possibilites to check the link.
精彩评论