Saturday, 3 March 2012

Firing up the default Browser

This simple snippet shows how to display a URL in a WPF window and fire up the default browser when the link is clicked.
Starting with a TextBlock in the XAML:
      <TextBlock>
         <Hyperlink Click="Hyperlink_Click"
                    NavigateUri="http://mikestedman.blogspot.com/2012/03/wpf-string-formatting.html">Link to original WPF Waltz blog entry</Hyperlink>
      </TextBlock>
And a simple event handler in the code-behind:
      private void Hyperlink_Click(object sender, RoutedEventArgs e)
      {
         Process.Start((sender as Hyperlink).NavigateUri.ToString());
      }

No comments: