Silverlight Out-of-Browser application will not close using MainWindow.Close method

≯℡__Kan透↙ 提交于 2019-12-05 04:29:51

The mistake is in the very first paragraph when you state that you "can only use this mechanism if one of these conditions is true:" Re-read the MS documentation a little closer and you will see that they do not say "one" of these conditions. Here is the exact text from the MS reference page for the Close method:

You can call this method only in the following cases:

  • In response to a user-initiated action, for example, in a button Click event handler.
  • Before the Application.Startup event has completed (that is, in an IApplicationService.StartService method, an IApplicationLifetimeAware.Starting method, or a Startup event handler).
  • In a trusted application.

As you have seen, you need to enable elevated trust.

UPDATE

I concede that the wording used by Microsoft is a bit misleading with either of the first two cases required in combination with the third. Perhaps it would be clearer if worded more accurately as:

You can call this method only in a trusted application in either of the following cases:

  • In response to a user-initiated action, for example, in a button Click event handler.
  • Before the Application.Startup event has completed (that is, in an IApplicationService.StartService method, an IApplicationLifetimeAware.Starting method, or a Startup event handler).

How to elevate permission for webBrowser control in silverlight:

1- http://msdn.microsoft.com/en-us/library/gg192793%28v=vs.96%29.aspx Topic: To enable in-browser trusted applications

2- http://www.johnpapa.net/digitally-signing-a-xap-silverlight/ Topic: Digitally Signing a XAP Silverlight

3- http://chainding.wordpress.com/2012/09/19/silverlight-5-trusted-applications/ Topic: Adding the required registry setting Signing your XAP file Deploying the certificate

And make sure the signed certificate is deployed in Trusted publisher of local machine and current user.

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