C# 如何在Windows Phone 8应用程序中处理呼叫

C# 如何在Windows Phone 8应用程序中处理呼叫,c#,windows-phone-8,C#,Windows Phone 8,我的应用程序使用一个定时器来震动设备。现在我想在接到呼叫时停止这个计时器,否则设备在呼叫期间也会继续振动,并在呼叫结束时再次启动它。我试图不加掩饰地处理这些事件 PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame; if (rootFrame != null) { rootFrame.Obscured += new EventHandler<ObscuredEventA

我的应用程序使用一个定时器来震动设备。现在我想在接到呼叫时停止这个计时器,否则设备在呼叫期间也会继续振动,并在呼叫结束时再次启动它。我试图不加掩饰地处理这些事件

PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;

if (rootFrame != null)
{
    rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
    rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}
PhoneApplicationFrame-rootFrame=App.Current.RootVisual作为PhoneApplicationFrame;
if(rootFrame!=null)
{
rootFrame.obclused+=新的事件处理程序(rootFrame\u obclused);
rootFrame.Unobscured+=新的事件处理程序(rootFrame\u Unobscured);
}

但这是行不通的。这些事件在接到呼叫时没有发生。我应该如何处理这个问题?

在App.xaml.cs中,有两种方法,如下所示。第一个在应用程序导航到时触发,第二个在您从应用程序导航时触发(例如,当您接到电话时)


您能告诉我如何停止app.xaml.cs中未声明的计时器吗。假设它在mainpage.xaml.cs中声明,您可以将计时器声明为public和static,然后按如下方式调用它:mainpage.TimerName
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    //start timer here
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    //stop timer here      
}