Silverlight 3 - Out of browser HtmlPage.Window.Navigate
Asked Answered
R

2

5

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...).

Reeva answered 9/10, 2009 at 8:28 Comment(0)
C
5

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/

Colenecoleopteran answered 9/10, 2009 at 10:39 Comment(1)
Your site doesn't render this answer. Should repost here.Thimbleful
B
2

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");

Bowing answered 5/2, 2013 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.