How to determine if a WPF page is hosted in a Browser

A WPF page can be host in a Web Browser, a Frame, or a NavigationWindow.

You can use BrowserInteropHelper.IsBrowserHosted to find out if a page is hosted in a browser.



if (BrowserInteropHelper.IsBrowserHosted)
{
// Yes hosted in a Browser
TextBox1.Text = "Is Browser Hosted: " + BrowserInteropHelper.Source.ToString();
}
else
{
TextBox1.Text = "Is not browser hosted";
}