1

在 Windows Phone 8 中,当我按下开始按钮时,我应该得到Application_DeactivatedApplication_Closing事件。但是当我在这些事件中设置断点时,断点没有命中。为什么Application_Closing并且Application_Deactivated没有被调用?

请参考

Occurs when an application stops being the foreground application.

应用程序.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>
4

1 回答 1

1

Deactivation这应该称为您放入enent 的内容。我建议阅读MSDN 的应用程序生命周期。信息量很大,这里就不贴了。

您当然可以在 Deactivation 事件中设置断点(根据评论中的讨论)。

但是当您点击开始按钮时不会调用关闭事件。

更多有用的链接:


如果您遇到问题,请检查 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>

如果您的应用程序设置为在后台运行(位置跟踪),则不会(立即)调用它。它可以在特定情况下调用。

于 2014-02-19T10:40:40.890 回答