Question

I need to open window pop-up from Silverlight Out-of-Browser application.

I've added parameter <param name="enablehtmlaccess" value="true" /> in Index.html, but executing this from code behind:

HtmlPage.Window.Navigate(new Uri(myUrl), "_blank", myFeatures);

still returns error:

Silverlight OOB Error: The DOM/scripting bridge is disabled.

I've read about this post, does it mean that I can't open pop-up from OOB? Why I need to do this, because actually I've shown the HTML page in OOB Silverlight by WebBrowser control within ChildWindow but when I click an anchor in HTML page, which linked to _blank page, it jumps to my default browser. It doesn't meet the requirement, except launch that HTML index page also in default browser at the first time, triggered from button control in OOB Silverlight. Is that possible?

Please advice, thanks.

Was it helpful?

Solution

No this is not possible. In an OOB application, any interaction with the HTML bridge is disabled.

OTHER TIPS

not sure if this is what you are after, but try this...

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

I came across this problem today and this is how I solved it in SilverLight 5: Create a new class with the following code:

/// <summary>
/// Opens a new browser window to the specified URL with the specified target
/// For use while running both in or out-of-browser
/// </summary>
public class WebBrowserBridge
{
    private class HyperlinkButtonWrapper : HyperlinkButton
    {
        public void OpenURL(String navigateUri, String target = "_blank")
        {
            OpenURL(new Uri(navigateUri, UriKind.Absolute), target);
        }

        public void OpenURL(Uri navigateUri, String target = "_blank")
        {
            base.NavigateUri = navigateUri;
            TargetName = target;
            base.OnClick();
        }
    }

    public static void OpenURL(String navigateUri, String target = "_blank")
    {
        HyperlinkButtonWrapper hlbw = new HyperlinkButtonWrapper();
        hlbw.OpenURL(navigateUri, target);
    }

    public static void OpenURL(Uri navigateUri, String target = "_blank")
    {
        HyperlinkButtonWrapper hlbw = new HyperlinkButtonWrapper();
        hlbw.OpenURL(navigateUri, target);
    }
} 

Here's how to both implement & use it:

private void hlViewMarketplace_Click(object sender, RoutedEventArgs e)
        {
            Uri destination = new Uri("http:///www.google.com/" + ((HyperlinkButton)sender).CommandParameter);
            WebBrowserBridge.OpenURL(destination, "_blank");
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top