Is there any possibility to programatically close Silverlight application on Windows Phone 7?
相关问题
- how to Enumerate local fonts in silverlight 4
- An error is occur when we use navigation to move o
- Free Silverlight mapping with Bing maps and OpenSt
- Custom number picker?
- Error using ResourceDictionary in Silverlight
相关文章
- Working with hmacsha256 in windows store app
- WP7 Alert dialog
- New Windows Application - What language?
- relative url in wcf service binding
- Add Service Reference and Add Web Reference?
- Embedded images not showing when in a UserControl
- Scrollviewer & SIP Issue (WP7.5 Mango)
- Database for Windows Phone 7 [closed]
You can always call an exit by doing this at your landing page use this code on click of your application back button:
This will remove back entries from the stack, and you will press a back button it will close the application without any exception.
Short answer for Silverlight is No.
You should not provide a way to close the applicaiton. Closing the applicaiton should be the users choice and implemented by using the back button the appropriate number of times. This is also a marketplace requirement.
That said, a silverlight application will close if there is an unhandled exception. I have seen a few people try and create programmatic closing by throwing a custom error which is explicitly ignored in error handling. This can work but there is still the marketplace issue.
XNA applications can explictly call
Exit()
.If you write an XNA Game, you will have access to an explicit Exit() method. If you are writing traditional Silverlight project, then NO, there is no way to programatically close your app. See also Peter Torr's Blog entry on Exiting Silverlight Apps in Windows Phone 7. There he also mentions the option of throwing an unhandled exception, which IMO is a terrible programing style.
An option you may try, is using the WP7 Navigation Service to programatically navigate back out of the application. Not sure if that would work though. Why do you need to Exit?
In Silverlight, I throw an un-handled exception when I have to exit the application. I know that this isn't the graceful method to handle this but it is still the most convenient and easiest solution.
I know that according to the guidelines there shouldn't be any un-handled exceptions in the code but I write why I am explicitly throwing an un-handled exception in the Exception Request document at the time of submission.
Till now this method has always worked and never failed me.
Navigate to
App.xaml.cs
in your solution explorer and add a static method to theApp
classso that you can call it anywhere from your application , as below