How to open window pop-up from Silverlight Out-of-Browser?

房东的猫 提交于 2019-12-21 21:17:06

问题


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.


回答1:


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




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/3021237/how-to-open-window-pop-up-from-silverlight-out-of-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!