This article shows that how to create a Hyperlink in WPF using VB. NET.
Hyperlink
There are two types to creating hyperlink in WPF.
The NavigateUri works only if we are placing the hyperlink within a page.
For example
XAML code
<Page
x:Class="WebPageNavigation.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Page1" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="159">
<Grid>
<TextBlock FontSize="20" TextWrapping="Wrap">
Welcome to <Hyperlink NavigateUri="http://www.vbdotnetheaven.com">Vbdotnetheaven.com</Hyperlink>
</TextBlock>
<Grid Margin="0,0,0,113"></Grid>
<TextBlock FontSize="20" TextWrapping="Wrap" Margin="0,52,0,68">
Welcome to <Hyperlink NavigateUri="http://www.c-sharpcorner.com">c-sharpcorner.com</Hyperlink></TextBlock>
</Grid>
</Page>
The form looks like this.
Figure 1.
Now click on the link Vbdotnetheaven.com.
Figure 2.
Now click on the link c-sharpcorner.com.
Figure 3.
To use it within a windows-based application we need to hanlde the RequestNavigate event and write the code.
For example
XAML code
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock FontSize="20"> Welcome to
<Hyperlink NavigateUri="http://www.vbdotnetheaven.com" RequestNavigate="Hyperlink_RequestNavigate">
Vbdotnetheaven.com
</Hyperlink>
</TextBlock>
</Grid>
</Window>
windows-based application we need to hanlde the RequestNavigate event and write the code.
Private Sub Hyperlink_RequestNavigate(ByVal sender As Object, ByVal e As RequestNavigateEventArgs)
Process.Start(New ProcessStartInfo(e.Uri.AbsoluteUri))
e.Handled = True
End Sub
Now run the application and test it.
Figure 4.
Now click on the link Vbdotnetheaven.com and test it.