How to link to external webpages (XAML)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Learn how to link to external webpages and display them in your Windows Runtime app using C# or Visual Basic.

Roadmap: How does this topic relate to others? See:

Prerequisites

You can add links to your app by using the HyperlinkButton control and setting its NavigateUri property.

To add a link to an external webpage:

  • Add a HyperlinkButton to your app by doing one of the following:
    • Drag a HyperlinkButton control onto a page's designer surface in Microsoft Visual Studio. Change the Content property to Search the web and set the NavigateUri property to https://www.bing.com.

    • Add this code to your app's XAML file.

      <HyperlinkButton NavigateUri="https://www.bing.com">Search the web</HyperlinkButton>
      

Displaying an external webpage in your app

Your Windows Runtime app can display an external webpage in a WebView, but you can't navigate from your top-level page to an external webpage. For a complete example of using the WebView, see the Webview sample.

To display a webpage in your app

  1. Add a WebView to your app by doing one of the following:

    • Drag a WebView control onto a page's designer surface in Microsoft Visual Studio 2012 and set the Name property to webView1.

    • Add this code to your app's XAML file.

      <WebView Name="webView1" Width="1000" Height="800"/>
      
  2. Add the next code to the code-behind file of the app. Where you place the code is up to you, depending on when you want to display the webpage. For example, you can add it to an OnNavigatedTo method to have the webpage load when the app loads. Or you can add it in a Click event handler to have the webpage load when a user clicks a button.

    The next example uses the WebView.Navigate method to display a webpage in a WebView.

    Uri targetUri = new Uri(@"https://www.bing.com");
    webView1.Navigate(targetUri);
    
    Dim uri As New Uri("https://www.bing.com")
    webView1.Navigate(targetUri)
    

Navigating between pages