Share via


BrowserInteropHelper.IsBrowserHosted 属性

定义

获取一个值,该值指定当前Windows Presentation Foundation (WPF) 应用程序是否托管浏览器。

public:
 static property bool IsBrowserHosted { bool get(); };
public static bool IsBrowserHosted { get; }
static member IsBrowserHosted : bool
Public Shared ReadOnly Property IsBrowserHosted As Boolean

属性值

如果该应用程序由浏览器承载,则为 true;否则为 false

示例

以下示例演示如何使用 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

注解

Page 可以是主机不可知,因此可加载到多种不同类型的主机,包括 FrameNavigationWindow 或浏览器。 如果库程序集包含一个或多个页面,并且由多个独立和可浏览(XAML 浏览器应用程序 (XBAP))主机应用程序引用,那么可能会发生这种情况。

适用于