WebBrowser Class
Updated: July 2008
Hosts and navigates between HTML documents. Enables interoperability between WPF managed code and HTML script.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The WebBrowser control provides the following capabilities:
Navigation: Source, Navigate, NavigateToStream, NavigateToString, Refresh, and Refresh.
Navigation Lifetime: Navigating, Navigated, and LoadCompleted.
Navigation Journaling: CanGoBack, GoBack, CanGoForward, and GoForward.
WPF/HTML Interoperability: InvokeScript and ObjectForScripting, and Document.
WebBrowser is bound by the security constraints of the WPF application that is hosting the WebBrowser:
When WebBrowser is hosted by a full-trust WPF application (a stand-alone application, for example), WebBrowser can host HTML documents from any location.
When WebBrowser is hosted by a partial-trust WPF application (an XBAP, for example), WebBrowser can only host documents that are Site Of Origin application data files. For more information, see Windows Presentation Foundation Application Resource, Content, and Data Files.
The following example shows how to configure WebBrowser to navigate to an HTML document by using markup only.
<!-- Web Browser Control that hosts a web page. --> <WebBrowser x:Name="webBrowser" Source="http://msdn.com" Width="600" Height="600" />
The following example shows how to configure WebBrowser to navigate to a document by using markup and code-behind.
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox x:Name="addressTextBox" Width="200" />
<Button Click="goNavigateButton_Click">Go</Button>
</StackPanel>
<WebBrowser x:Name="myWebBrowser" />
</StackPanel>
private void goNavigateButton_Click(object sender, RoutedEventArgs e)
{
// Get URI to navigate to
Uri uri = new Uri(this.addressTextBox.Text, UriKind.RelativeOrAbsolute);
// Only absolute URIs can be navigated to
if (!uri.IsAbsoluteUri)
{
MessageBox.Show("The Address URI must be absolute eg 'http://www.microsoft.com'");
return;
}
// Navigate to the desired URL by calling the .Navigate method
this.myWebBrowser.Navigate(uri);
}
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.