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

非 Y 不嫁゛ 提交于 2019-12-04 16:19:45

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

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