WPF

WPF LinkLabel

Jose Leon
Author

WPF doesn't include a control that displays a hyperlink like LinkLabel that was included in Windows Forms. But still, this kind of control is really important and can have a lot of uses around our applications.

What I have done below is simply combine multiple WPF controls to recreate a simple LinkLabel that you can actually click and browse to some address on the Internet. Below you can find the XAML markup:

           The link Text

And this is the C# code:

namespace WpfApplication9{    ///     /// Interaction logic for MainWindow.xaml    ///     public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();        }        private void Hyperlink_Click(object sender, RoutedEventArgs e)        {            System.Diagnostics.Process.Start(LinkLabel.NavigateUri.ToString());        }    }}

In the code above I'm just creating a TextBlock and adding the Hyperlink inside of it. Then defining the NavigateUri property with some url and then adding the text. In the C# code, we're just handling the click and opening a process and passing the url as a parameter. This will open the default browser with the link.

features

All posts

  • licensing
  • analytics

Easy .NET Protection

Purchase template