HOW TO:決定是否由瀏覽器裝載頁面
這個範例示範如何判斷 Page 是否已裝載於瀏覽器中。
範例
Page 可以與主應用程式無關,因此可以載入至數個不同類型的主應用程式,包括 Frame、NavigationWindow 或瀏覽器。 這會發生在您的程式庫組件包含一頁或多頁,並且由多個獨立和可瀏覽的 (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";
}