Updated: July 2008
Hosts and navigates between HTML documents. Enables interoperability between WPF managed code and HTML script.
Namespace:
System.Windows.Controls
Assembly:
PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
Public NotInheritable Class WebBrowser _
Inherits ActiveXHost _
Implements IKeyboardInputSink
Dim instance As WebBrowser
public sealed class WebBrowser : ActiveXHost,
IKeyboardInputSink
public ref class WebBrowser sealed : public ActiveXHost,
IKeyboardInputSink
public final class WebBrowser extends ActiveXHost implements IKeyboardInputSink
XAML Object Element Usage
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);
}
System..::.Object
System.Windows.Threading..::.DispatcherObject
System.Windows..::.DependencyObject
System.Windows.Media..::.Visual
System.Windows..::.UIElement
System.Windows..::.FrameworkElement
System.Windows.Interop..::.HwndHost
System.Windows.Interop..::.ActiveXHost
System.Windows.Controls..::.WebBrowser
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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.
.NET Framework
Supported in: 3.5 SP1, 3.0 SP2
Reference
Other Resources
Date | History | Reason |
|---|
July 2008
| Added topic for new class. |
SP1 feature change.
|