Windows Phone 8.1 Working with the app from the Close button on the page

In my Windows Phone app, I have to delete some files when the user navigates away from the page. I handled this on the OnBackKeyPress event. This works great. The problem is with the newer Windows Phone 8 and Windows Phone 8.1 updates, and there is also a close button in the upper right corner. I have not found a way to handle this event. Can someone please let me know how I can handle this event and delete files.

+3


source to share


1 answer


Instead of using OnBackKeyPress, you should use OnNavigatedFrom. This event fires whenever the user leaves the page, no matter how.


If you need to handle only a specific case in which the application is suspended / finished, you can subscribe to events Deactivated

and Closing

in PhoneApplicationService.



PhoneApplicationService.Current.Deactivated += yourHandler;

      

Note that an event handler is a non-static method declared on your page, so you must unsubscribe from the event when you leave the page to avoid a memory leak. To find out when to unsubscribe, you can follow the OnBackKeyPress logic.

+1


source







All Articles