Como: Determine If a Page is Browser Hosted

This example demonstrates how to determine if a Page is hosted in a browser.

Exemplo

A Page can be host agnostic and, consequently, can be loaded into several different types of hosts, including a Frame, a NavigationWindow, or a browser. This can happen when you have a library assembly that contains one or more pages, and which is referenced by multiple standalone and browsable (XAML browser application (XBAP)) host applications.

The following example demonstrates how to use BrowserInteropHelper.IsBrowserHosted to determine if a Page is hosted in a browser.

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

Consulte também

Referência

Frame

Page