如何:确定页是否以浏览器为宿主

此示例演示如何确定 Page 是否是在浏览器中承载的。

示例

Page 可以是与主机无关,因此,可以加载至不同类型的主机,包括 FrameNavigationWindow 或浏览器。 当您具有包含一个或多个页面的库程序集时,并且这个程序集是由多个独立和可浏览的 (XAML browser application (XBAP)) 主机应用程序引用的,可能会出现此情况。

下面的示例演示如何使用 BrowserInteropHelper.IsBrowserHosted 来确定 Page 是否是在浏览器中承载的。

      ' 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
// 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";
}

请参见

参考

Frame

Page