在Windows Phone 8中,当我按下开始按钮时,我应该收到Application_Deactivated
和Application_Closing
个事件。但是当我在这些事件中设置断点时,断点不会被击中。为什么Application_Closing
和Application_Deactivated
没有被调用?
Occurs when an application stops being the foreground application.
的App.xaml
<Application
x:Class="ContineousLocationTracking.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:ContineousLocationTracking" x:Key="LocalizedStrings"/>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"
RunningInBackground="PhoneApplicationService_RunningInBackground"
/>
</Application.ApplicationLifetimeObjects>
</Application>
答案 0 :(得分:1)
应该调用你放入Deactivation
内的内容。我建议你阅读Application lifecycle at MSDN。有很多信息,所以我不会在这里发布。
你肯定可以在Deactivation事件中设置断点(根据评论中的讨论)。
但是当你点击Start buton时没有调用Closing事件。
更有用的链接:
如果遇到问题,请检查App.xaml是否使用了这些事件:
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
如果您的应用程序设置为在后台运行(位置跟踪),则不会立即调用它。它可以在specific circumstances中调用。