Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight 3 - Out of browser HtmlPage.Window.Navigate

Silverlight 3 allows you to run your application out of the browser, which installs a link on your desktop/start menu.

The problem is we are currently using

System.Windows.Browser.HtmlPage.
  Window.Navigate(new Uri("http://<server>/<resource>"), "_blank")

to load a URL into a new browser window (it's to provide a 'print friendly' page for users to print). This works in the normal SL in-browser version, but outside the browser we get 'The DOM/scripting bridge is disabled.' exception thrown when issuing the call.

Is there an alternative which works out of the browser?

I've seen Open page in silverlight out of browser but I need to do this entirely in code, so I don't want to add a (hidden) hyperlink button and then programmatically 'click' it (unless I absolutely have to...).

like image 508
Mark Pim Avatar asked Oct 09 '09 08:10

Mark Pim


2 Answers

you can try inheriting from HyperlinkButton and exposing public Click() method (which you can then instantiate and call from code instead of declaring it in xaml). Details here: http://mokosh.co.uk/post/2009/10/08/silverlight-oob-open-new-browser-window/

like image 134
Jarek Kardas Avatar answered Oct 12 '22 10:10

Jarek Kardas


I wrote an Extension method based on the idea to inherit from the HyperlinkButton.

public static class UriExtensions {

class Clicker : HyperlinkButton {
  public void DoClick() {
    base.OnClick();
  }
}

static readonly Clicker clicker = new Clicker();

public static void Navigate(this Uri uri) {
  Navigate(uri, "_self");
}

public static void Navigate(this Uri uri, string targetName) {
  clicker.NavigateUri = uri;
  clicker.TargetName = targetName;
  clicker.DoClick();
}
}

Then use can use it simple, like

new Uri("http://www.google.com").Navigate("_blank");

like image 33
Alexander Zwitbaum Avatar answered Oct 12 '22 09:10

Alexander Zwitbaum