2014-02-19 98 views
1

在Windows Phone 8中,當我按下開始按鈕時,我應該得到Application_DeactivatedApplication_Closing事件。但是當我在這些事件中設置斷點時,斷點不會命中。爲什麼Application_ClosingApplication_Deactivated沒有被調用?爲什麼應用程序沒有收到應用程序關閉事件?

Please refer

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

這些方法中是否有任何代碼?因爲如果它們是空的,編譯器可以刪除它們。 – xmashallax

+0

你是如何設置這些事件的? – CathalMF

+0

@xmashallax不,我在事件中有代碼 –

回答

1

這就是你投入Deactivation enent應該叫。我建議閱讀Application lifecycle at 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> 

,它不會被調用(瞬間)如果您的應用程序設置爲運行背景(位置跟蹤)。它可以在specific circumstances中調用。

+0

'停用事件也沒有被調用。 –

+0

@pranitkothari看我的編輯並檢查你的App.xaml。 – Romasz

+0

做過同樣的事情,但bp沒有命中。 –

相關問題