To user hyperlink in WPF application we could do something like this
<TextBlock>
<Hyperlink NavigateUri=”http://www.google.co.in”>
Click here
</Hyperlink>
</TextBlock>
However the NavigateUri works only if we are placing the hyperlink within a page. To use it within a windows-based application we need to hanlde the RequestNavigate event and write the code ourselves.
Something like this
<TextBlock>
<Hyperlink NavigateUri=”http://www.google.co.in” RequestNavigate=”Hyperlink_RequestNavigate”>
Click here
</Hyperlink>
</TextBlock>
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
While using hyperlink we could also provide handler for Application.NavigationFailed event in case if navigation fails.
That’s it ….
Very helpful. Just want to add that
Application.NavigationFailed EventHandler goes into the App.Xaml class and might look like this:
private void App_NavigationFailed (object sender, NavigationFailedEventArgs e)
{
if (e.Exception is System.Net.WebException)
{
//code to handle error here, such as a messagebox to the user
e.Handled = true;
}
}
LikeLike
Hi,
I am Naga Harish from chennai. I need one help from you. I want write Microsoft certification in ASP.Net. I need your guide lines. You can my gmail ID to send reply (nagaharish.movva@gmail.com) . I have some Q? too. Please help me!
LikeLike
This doesnt seem to work unless i add a this.DataContext = “something” into my main window class. this is causing issues for me as i have a relativesource binding set to my datacontext in the xaml. how can i get around this? thanks! great article btw
LikeLike
Hi,
Just one question, please….
In the code line “Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));”… what stands for Process?? I´m trying to write your code and I got an error regarding that line…
Thanks in advance
LikeLike
thanks. but for me it works only like this
Process.Start(new ProcessStartInfo(“mailto:”+e.Uri.ToString()));
LikeLike
I’m using the code below. I hope it can help you.
Click here!
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
LikeLike
Thanks. This helped me solve a problem
LikeLike
Here it explains how to use Hyperlink control in WPF:
http://codeskaters.blogspot.ae/2013/10/wpf-how-to-use-hyperlink.html
LikeLike
Good day! I know this is somewhat off topic but I was wondering if you
knew where I could locate a captcha plugin for my comment form?
I’m using the same blog platform as yours and I’m having difficulty finding one?
Thanks a lot!
LikeLike
I need to open my link with wpf application
LikeLike
I need to open a link with wfp application via outlook sendingand receive email.
LikeLike