How to open a popup from Silverlight Out-of-Browser?

I need to open a popup from a Silverlight Out-of-Browser application.

I added a parameter <param name="enablehtmlaccess" value="true" />to Index.html, but executed this from the code:

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

still returns an error:

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

I read about this article, does this mean that I cannot open a popup from OOB? Why do I need this, because in fact I showed the HTML page in OOB Silverlight using the control WebBrowserin ChildWindow, but when I click on the anchor link on the HTML page that is associated with the _blank page, it goes to my default browser, It does not meet the requirements, except that for the first time this HTML index page is launched in the default browser, invoked using the control button in OOB Silverlight. Is it possible?

I ask for advice, thanks.

+3
source share
3 answers

, . OOB HTML .

+2

, , , ...

OOB :

, :

public class MyHyperlinkButton : HyperlinkButton 
{ 
        public void ClickMe() 
        { 
                base.OnClick(); 
        } 
} 

:

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

. forums.silverlight.net

+3

, SilverLight 5: :

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

:

private void hlViewMarketplace_Click(object sender, RoutedEventArgs e)
        {
            Uri destination = new Uri("http:///www.google.com/" + ((HyperlinkButton)sender).CommandParameter);
            WebBrowserBridge.OpenURL(destination, "_blank");
        }
+2

Source: https://habr.com/ru/post/1749531/


All Articles