Within the browser I can use this to open a pop开发者_开发百科-up window:
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(uri), "_blank");
How do I do this when running outside of the browser?
In an OOB app, you can use the following work around:
Create a derived hyperlink button like this:
public class MyHyperlinkButton : HyperlinkButton
{
public void ClickMe()
{
base.OnClick();
}
}
Use that for navigation:
private void NavigateToUri(Uri url)
{
if (App.Current.IsRunningOutOfBrowser)
{
MyHyperlinkButton button = new MyHyperlinkButton();
button.NavigateUri = url;
button.TargetName = "_blank";
button.ClickMe();
}
else
{
System.Windows.Browser.HtmlPage.Window.Navigate(url, "_blank");
}
}
see forums.silverlight.net
You don't. System.Windows.Browser.HtmlPage is a call to the HtmlPage that is hosting the silverlight application. In out of Browser, you are not hosted by a web page. Trying to do that just hangs the application.
If you have elevated privileges, than you could make an OS call to open a new browser, or I'm sure there are 3rd party controls that act as a hosted browser.
Another way to do this is through ShellExecute:
if (App.Current.IsRunningOutOfBrowser)
{
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
shell.ShellExecute("someURL", "", "", "open", 1);
}
Documentation for ShellExecute is here: http://msdn.microsoft.com/en-us/library/bb774148(VS.85).aspx
精彩评论