Language: HTML | XAML

How to link to external webpages (XAML)

Applies to Windows and Windows Phone

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

Creating a link to an external webpage

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 http://www.bing.com.
    • Add this code to your app's XAML file.

      
      <HyperlinkButton NavigateUri="http://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.

Hh868173.wedge(en-us,WIN.10).gifTo 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.

    Dim uri As New Uri("http://www.bing.com")
    webView1.Navigate(targetUri)
    
    

Related topics

Navigating between pages

 

 

Show:
© 2014 Microsoft