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:
- Roadmap for Windows Runtime apps using C# or Visual Basic
- Roadmap for Windows Runtime apps using C++
- We assume that you can create a basic Windows Runtime app using C# or Visual Basic. For instructions on creating your first Windows Runtime app, see Create your first Windows Runtime app using C# or Visual Basic.
Creating a link to an external webpage
To add a link to an external webpage:
- Add a HyperlinkButton to your app by doing one of the following:
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.
To display a webpage in your app
Add a WebView to your app by doing one of the following:
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.
Uri targetUri = new Uri(@"http://www.bing.com"); webView1.Navigate(targetUri);
Dim uri As New Uri("http://www.bing.com") webView1.Navigate(targetUri)