Launch Internet Explorer from HyperlinkButton in Windows 8 Metro app

If you are building a Metro app for Windows 8 with XAML/C# and need to launch your link in a browser, there is HyperlinkButton control but you need to wire up the Click event and launch it from the codebehind file.

So I ended up doing something like this

   1: <HyperlinkButton 

   2: x:Name="Readmore" 

   3: Click="Readmore_OnClick" 

   4: Tag="{Binding Link}" 

   5: Content="Read more.." />

I am using the Tag property to bind my link and get it in the code like this.

   1: private void Readmore_OnClick(object sender, RoutedEventArgs e)

   2: {

   3:   var link = (HyperlinkButton) e.OriginalSource;

   4:   Windows.System.Launcher.LaunchUriAsync(new Uri(link.Tag.ToString()));

   5: }

The above Launcher class can be used to load files stored locally on the device.

FacebookTwitterLinkedInEmailGoogle+
  • Pingback: Interesting Windows 8 Links – 2012-04-11 | Dan Rigby

  • wloescher

    Finally figured out correct syntax for a JavaScript hyperlink:
    <a href=”#” data-win-bind=”href: linkUrl; textContent: linkUrl”></a>

  • Anonymous

    Finally figured out correct syntax for a JavaScript hyperlink:
    <a href=”#” data-win-bind=”href: linkUrl; textContent: linkUrl”></a>

  • http://blog.notallwork.com/ Marc

    Thanks for the help!

  • http://blog.notallwork.com/ Marc

    Thanks for the help!

  • Neo

    Thanks a ton man !! I needed it real quick !!

  • Neo

    Thanks a ton man !! I needed it real quick !!

  • Rjgood

    Thanks a ton, was stuck looking for a code-based solution!

  • Rjgood

    Thanks a ton, was stuck looking for a code-based solution!

  • mPedro

    Thank you very good post

  • Saykor

    Why you just not use: NavigateUri=”{Binding Link}” ?