1

I have included a browser control in a WPF app I'm working on and when hyperlinks in the displayed web page are clicked nothing happens. To go to another page I have to right-click on the link and select open. Any ideas why?

2 Answers2

2

I think you need to handle the RequestNavigate event:

link.RequestNavigate += (sender, e) =>
{
    System.Diagnostics.Process.Start(e.Uri.ToString());
};

Reference: C# Hyperlink in TextBlock: nothing happens when I click on it

Community
  • 1
  • 1
Syed Shoaib Abidi
  • 2,356
  • 17
  • 19
  • Thanks again. But how to I capture this event when it occurs in a web browser? – mattvanleuten Apr 05 '14 at 14:28
  • Try the steps under the heading **To create a hyperlink in a portion of a TextBlock** in the following link and see if that helps you: http://msdn.microsoft.com/en-us/library/cc304466.aspx – Syed Shoaib Abidi Apr 05 '14 at 14:35
  • Sorry, I'm not really understanding... the web browser is displaying a web site - doesn't the method in your link require adding each hyperlink seperately? – mattvanleuten Apr 05 '14 at 14:42
  • I'm sorry @Shoaib Raza - it seems as though the problem is with the website... if I change to different websites, it works on some and not on others. I'll have to carry on researching... – mattvanleuten Apr 05 '14 at 15:04
1

I don't know if Syed Shoaib Abidi's answer is just different syntax for the same thing, but:

link.RequestNavigate += UrlClicked;

...
private void Url_Clicked(object sender, RequestNavigateEventArgs e)
{
Process.Start(e.Uri.ToString());
}
Marcus
  • 116
  • 11