此示例演示如何确定Page是否在浏览器中托管。
警告
XBAP 要求旧版浏览器运行,例如 Internet Explorer 和旧版 Firefox。 这些较旧的浏览器通常在 Windows 10 和 Windows 11 上不受支持。 由于安全风险,新式浏览器不再支持 XBAP 应用所需的技术。 不再支持启用 XBAP 的插件。 有关详细信息,请参阅 有关 WPF 浏览器托管应用程序(XBAP)的常见问题解答。
示例:
Page 可以与主机无关,因此,它可以加载到多种不同类型的主机中,包括 Frame、NavigationWindow 或浏览器。 如果库程序集包含一个或多个页面,并且由多个独立和可浏览的(XAML 浏览器应用程序(XBAP)托管应用程序引用,则可能会发生这种情况。
以下示例演示如何使用 BrowserInteropHelper.IsBrowserHosted 来确定 Page 是否托管在浏览器中。
// Detect if browser hosted
if (BrowserInteropHelper.IsBrowserHosted)
{
// Note: can only inspect BrowserInteropHelper.Source property if page is browser-hosted.
this.dataTextBlock.Text = "Is Browser Hosted: " + BrowserInteropHelper.Source.ToString();
}
else
{
this.dataTextBlock.Text = "Is not browser hosted";
}
' Detect if browser hosted
If BrowserInteropHelper.IsBrowserHosted Then
' Note: can only inspect BrowserInteropHelper.Source property if page is browser-hosted.
Me.dataTextBlock.Text = "Is Browser Hosted: " & BrowserInteropHelper.Source.ToString()
Else
Me.dataTextBlock.Text = "Is not browser hosted"
End If