Xamarin.Forms Guides | Samples

Xamarin.Forms.WebView Class

A View that presents HTML content.

See Also: WebView

Syntax

[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._WebViewRenderer))]
public class WebView : View, IElementConfiguration<WebView>

Remarks

The following example shows a basic use.

C# Example

using System;
using Xamarin.Forms;

namespace FormsGallery
{
    class WebViewDemoPage : ContentPage
    {
        public WebViewDemoPage()
        {
            Label header = new Label
            {
                Text = "WebView",
                FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };

            WebView webView = new WebView
            {
                Source = new UrlWebViewSource
                {
                    Url = "http://blog.xamarin.com/",
                },
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            // Build the page.
            this.Content = new StackLayout
            {
                Children =
                {
                    header,
                    webView
                }
            };
        }
    }
}

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.WebView are listed below.

See Also: View

Public Constructors

Creates a new WebView element with default values.

Public Fields

static readonly
CanGoBackPropertyBindableProperty. Backing store for the WebView.CanGoBack property.
static readonly
CanGoForwardPropertyBindableProperty. Backing store for the WebView.CanGoForward property.
static readonly
SourcePropertyBindableProperty. Backing store for the WebView.Source property.

Public Properties

[read-only]
CanGoBackBoolean. Gets a value that indicates whether the user can navigate to previous pages.
[read-only]
CanGoForwardBoolean. Gets a value that indicates whether the user can navigate forward.
SourceWebViewSource. Gets or sets the WebViewSource object that represents the location that this WebView object displays.

Public Methods

Eval(String)
Evaluates the script that is specified by script.
GoBack()
Navigates to the previous page.
GoForward()
Navigates to the next page in the list of visited pages.
On<T>() : IPlatformElementConfiguration<T, WebView>
Returns the platform-specific instance of this WebView, on which a platform-specific method may be called.

Protected Methods

override
OnBindingContextChanged()
override
OnPropertyChanged(String)
Method that is called when WebView.Source is changed.
OnSourceChanged(Object, EventArgs)
Method that is called when the view source that is specified by the sender parameter is changed.

Public Events

NavigatedEvent that is raised after navigation completes.
NavigatingEvent that is raised when navigation starts.