C# Hyperlink in TextBlock: nothing happens when I click on it
You need to handle the hyperlink's RequestNavigate
event. Here's a quick way of doing it:
link.RequestNavigate += (sender, e) =>{ System.Diagnostics.Process.Start(e.Uri.ToString());};
Are you handling the 'Hyperlink.RequestNavigate' event? When a user clicks a Hyperlink in a WPF window it doesn't automatically open a browser with the URI specified in its NavigateUri property.
In your code-behind you can do something like:
link.RequestNavigate += LinkOnRequestNavigate;private void LinkOnRequestNavigate(object sender, RequestNavigateEventArgs e){ System.Diagnostics.Process.Start(e.Uri.ToString());}
You can make a global hyperlink handler in your App.xaml.cs
protected override void OnStartup(StartupEventArgs e) { EventManager.RegisterClassHandler( typeof(System.Windows.Documents.Hyperlink), System.Windows.Documents.Hyperlink.RequestNavigateEvent, new System.Windows.Navigation.RequestNavigateEventHandler( (sender, en) => System.Diagnostics.Process.Start(en.Uri.ToString()) ) ); base.OnStartup(e);}
This assumes all the NavigateUri properties refer to something you want to launch, but you can always make the handler take care of edge cases.