我正在 Windows Phone 中开发一个应用程序。在我的应用程序中,有必要处理锁定按键事件,因为我使用了 Timer。这是我的代码
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
PhoneApplicationService.Current.Activated += Micropphone_Current_Activated;
PhoneApplicationService.Current.Deactivated += Micropphone_Current_Deactivated;
if (_autowizardtimer != null)
{
_autowizardtimer.Stop();
_autowizardtimer.Tick -= _timer_Tick;
if (_endtimer != null)
{
_endtimer.Stop();
_endtimer.Tick -= _endtimer_Tick;
}
}
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
if (_autowizardtimer != null)
{
PhoneApplicationService.Current.Activated -= Micropphone_Current_Activated;
PhoneApplicationService.Current.Deactivated -= Micropphone_Current_Deactivated;
_autowizardtimer.Stop();
_autowizardtimer.Tick -= _timer_Tick;
}
if (_endtimer != null)
{
_endtimer.Stop();
_endtimer.Tick -= _endtimer_Tick;
}
}
基本上我想做的是,当用户按下锁定键时,计时器暂停,释放锁定键后,计时器开始计时。问题出在OnNavigatedFrom
方法上。当我按下锁定键时,此方法不会调用。我没有得到什么问题。有人能说出为什么会这样吗?或者有没有其他方法来处理锁定按键?