Delen via


WebView Execution Mode on Windows

This platform-specific sets the thread on which a WebView hosts its content. It's consumed in XAML by setting the WebView.ExecutionMode bindable property to a WebViewExecutionMode enumeration value:

<ContentPage ...
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout>
        <WebView ... windows:WebView.ExecutionMode="SeparateThread" />
        ...
    </StackLayout>
</ContentPage>

Alternatively, it can be consumed from C# using the fluent API:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
...

WebView webView = new Xamarin.Forms.WebView();
webView.On<Windows>().SetExecutionMode(WebViewExecutionMode.SeparateThread);

The WebView.On<Windows> method specifies that this platform-specific will only run on the Universal Windows Platform. The WebView.SetExecutionMode method, in the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace, is used to set the thread on which a WebView hosts its content, with the WebViewExecutionMode enumeration providing three possible values:

  • SameThread indicates that content is hosted on the UI thread. This is the default value for the WebView on Windows.
  • SeparateThread indicates that content is hosted on a background thread.
  • SeparateProcess indicates that content is hosted on a separate process off the app process. There isn't a separate process per WebView instance, and so all of an app's WebView instances share the same separate process.

In addition, the GetExecutionMode method can be used to return the current WebViewExecutionMode for the WebView.