Windows phone 7 WP7 Silverlight应用程序中的计数器

Windows phone 7 WP7 Silverlight应用程序中的计数器,windows-phone-7,counter,Windows Phone 7,Counter,我正在用c#silverlight编写扫雷游戏。 1.如何将计数器(仅计数秒)添加到此应用程序? 2.当应用程序转到后台(中间按钮、搜索按钮、来电等)时,如何停止计数器? 3.当WP7关闭我的申请过程时,我该如何做?例如,将当前游戏保存到独立存储。1)您需要使用 2) 您需要处理OnNavigatedFrom事件: private void Application_Deactivated(object sender, DeactivatedEventArgs e) { //Do some

我正在用c#silverlight编写扫雷游戏。
1.如何将计数器(仅计数秒)添加到此应用程序?
2.当应用程序转到后台(中间按钮、搜索按钮、来电等)时,如何停止计数器?
3.当WP7关闭我的申请过程时,我该如何做?例如,将当前游戏保存到独立存储。

1)您需要使用

2) 您需要处理OnNavigatedFrom事件:

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    //Do something
}
3) 这里有4个有用的事件:

    // Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
    //Do something
}

// 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)
{
    //Do something
}

// 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)
{
    //Do something
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
    //Do something
}
在此处,您可以阅读有关处理此事件的更多信息:

    // Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
    //Do something
}

// 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)
{
    //Do something
}

// 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)
{
    //Do something
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
    //Do something
}