Silverlight App inside WPF WebBrowser?

落爺英雄遲暮 提交于 2019-12-12 10:59:38

问题


I have a hopefully trivial question. Currently, my company works with a rather obscure language (SyngergyDE) and we need to call a SilverLight application inside our product. Unfortunately, this obscure 3rd party language only (currently) supports the opening of WPF screens. So with that said, I thought I'd develop a small WPF user control that contains a "WebBrowser" control and navigate to the silverlight application's URI. This works fine, and I'm able to see the SL application. Here is my question - we have a "Close" button on the SL application, and when users "Click" that button, we want the window to close.

Does anyone have any suggestions on how we can communicate the "Closing of the SL App" to the WPF user control, so that the entire WPF user control closes as well?

Thanks everyone,

-Tom


回答1:


Attach an event handler to the WebBrowser.Navigated event.

Have the close button in the Silverlight application use:-

 HtmlPage.Window.Navigate(new Uri("about:blank", UriKind.Absolute));

When the Navigated event fires in WPF with the url "about:blank" then its time to close the control.




回答2:


Use Javascript and the HTML DOM as the glue here.

For example, when the SL app close button is clicked, have Silverlight trigger some Javascript code that sets a flag, or alternately, raises some HTML document event.

The WPF control could poll that flag in the HTML + Javascript, or alternately listen for that HTML document event, then close the user control.



来源:https://stackoverflow.com/questions/4215850/silverlight-app-inside-wpf-webbrowser

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