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.

5 Comments to “Launch Internet Explorer from HyperlinkButton in Windows 8 Metro app”

  1. [...] TLDR Version: If you’ve used DataBinding in WPF or Silverlight, it is very familiar.”Launch Internet Explorer from HyperlinkButton in Windows 8 Metro app (Zubair Ahmed)“If you are building a Metro app for Windows 8 with XAML/C# and need to launch [...]

  2. Anonymous says:

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

  3. Marc says:

    Thanks for the help!

  4. Neo says:

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

  5. Rjgood says:

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

Leave a Reply

You must be logged in to post a comment.