Silverlight 3 - From the HtmlPage.Window.Navigate Browser

Silverlight 3 allows you to launch your application from a browser , which sets the link on the desktop / start menu.

The problem is that we are currently using

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

to load the URL into a new browser window (so that it provides printing for printing). This works in the normal SL version in the browser, but outside the browser we get "DOM / scripting bridge disabled." an exception that occurred when calling a call.

Is there an alternative that works in the browser?

I saw Open a page in silverlight from a browser , but I need to do this completely in code, so I don’t want to add a (hidden) hyperlink button, and then programmatically 'click' (if I don’t have to ...).

+5
source share
2 answers

you can try to inherit from HyperlinkButton and expose the public Click () method (which you can then create 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/

+5
source

I wrote an extension method based on the idea of ​​inheritance using 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 just like

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

+2
source

All Articles