共用方式為


Windows 上的 WebView 執行模式

此平臺特定會設定裝載其內容的線程 WebView 。 將可繫結屬性設定 WebView.ExecutionModeWebViewExecutionMode 列舉值,以在 XAML 中取用:

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

或者,您可以使用 Fluent API 從 C# 取用它:

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

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

方法WebView.On<Windows>會指定這個平臺專用只會在 通用 Windows 平台 上執行。 命名空間 WebView.SetExecutionMode 中的 Xamarin.Forms.PlatformConfiguration.WindowsSpecific 方法可用來設定裝載其內容的線程 WebView ,而 WebViewExecutionMode 列舉會提供三個可能的值:

  • SameThread 表示內容裝載在UI線程上。 這是 Windows 上的 預設值 WebView
  • SeparateThread 表示內容裝載在背景線程上。
  • SeparateProcess 表示內容裝載於應用程式進程外的個別進程上。 每個 WebView 實例沒有個別的進程,因此所有應用程式的 WebView 實例都會共用相同的個別進程。

此外,GetExecutionMode方法可以用來傳回 的WebView目前 WebViewExecutionMode