I'm building a chat application and I am parsing out links and adding them to the chatroom view with Hyperlinks. These Hyperlinks have the following event handler set to them:
void urlLink_Click(object sender, RoutedEventArgs e)
{
try
{
Hyperlink link = sender as Hyperlink;
this.chatUI.DisplayWebBrowser(link.NavigateUri);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
Whether or not the event gets triggered seems to be random though. Some links will work as intended when clicked, while some links will not work. Some links work to start with but after more messages are received, they stop working. Anyone know what's the cause and how to solve this? This is how the Hyperlink control is being created:
newSpan = new Span();
Run urlRun = new Run();
urlRun.Text = urlMatches[i].Value;
Hyperlink urlLink = new Hyperlink();
urlLink.NavigateUri = new Uri(urlMatches[i].Value, UriKind.Absolute); // Add URI to the Hyperlink control
urlLink.Click += urlLink_Click; // Add event handler to control
urlLink.Inlines.Add(urlRun); // Add text to Hyperlink