WebView is the primary managed wrapper of an Awesomium Web-View. It is provided through the Awesomium.Core assembly on MS Windows and also through Awesomium.Mono (platform independent) and Awesomium.Unity.Core (Unity game engine). It can be used in any technology.
WebView is mainly used as a windowless web-view component in applications without GUI (Console applications, services etc.), MVVM applications or managed technologies where Awesomium.NET does not already provide a web-view component.
WebView can be of any type, offscreen or windowed. For more details read Introduction to Web-Views.
Creating a WebView
WebView instance can only be created through the
WebCore, using any of the following methods:
WebCore.CreateWebView(Int32, Int32, WebSession)
WebCore.CreateWebView(Int32, Int32, WebViewType)
WebCore.CreateWebView(Int32, Int32, WebSession, WebViewType)
Here are some examples:
Here’s an example of how to create a windowed
WebView to be used in a Windows Forms application:
The primary way to load content into any
IWebView instance, is via the
IWebView.Source property. For example, to begin navigating a
WebView to Google, you would call:
All URLs should be properly formatted before attempting to create a
Uri. You can check if a URL is valid via
System.Uri.IsWellFormedUriString. The .NET Framework also provides the
System.UriBuilder utility class, to create or modify complicated URIs. Additionally, in Awesomium.NET we have added an extension method to the
String class, for creating URIs. Here is how to use it:
Note however that this may fail if the specified string is not a well formatted URL. In this case,
ToUri fails silently and returns a blank URI (
IWebView.Source makes it really easy to load remote content on the Internet, but what about local resources? If you would like to load local resources with your application, we recommend using a
DataSource. This powerful bit of API allows you to provide a custom resource loader for a set of URLs that match a certain prefix.
See this article for an introduction to
DataSource and the available, predefined
DataSource classes that come with Awesomium.NET.
Displaying the WebView
WebView component is displayed, depends on its type.
WebView components can be displayed to Windows Forms and WPF using any of the predefined
ISurface classes available with Awesomium.NET. For more advanced scenarios or for displaying a
WebView in technologies where Awesomium.NET does not already provide a web-view component, you can create a custom
WebView components, render directly to a platform window (
NSView, etc.) and capture all input themselves. In certain technologies, resizing is also handled automatically.
For more details, read:
IWebView instances implement
IDisposable and expose a
Dispose method. For details about how to properly dispose a
WebView, read the Cleaning Up section in Introduction to Web-Views.