如何在WP中重新激活应用程序时刷新日期时间



我想知道当应用程序从WP7.5中的停用状态返回时,是否可以刷新日期时间。我的应用程序基本上是一种日历类型,当应用程序启动时,会突出显示当前日期。

因此,如果我启动应用程序,然后按下启动按钮,我的应用程序将进入停用状态,然后转到设置并更改时区,自然日期和时间可能会更改,然后返回我的应用,它将保留旧日期。

例如。假设当前日期是20,我们更改日期为19的时区,理想情况下,我的应用程序应该突出显示19,但它没有。我假设它在应用程序进入停用状态之前变为,它存储所有状态,当它返回时,它加载相同的数据。还有什么可以刷新日期时间的吗?

阿尔法

我已经有一段时间没有进行任何WP7开发了,但我确信当应用程序被重新激活时会引发一个事件——那时你不能只查询DateTime.NowDateTime.Today吗?

编辑:看看文档,我想你想要启动和激活事件。(Launching,即使在初次启动时也可以检查时间;Activated,在休眠后重新激活。)

假设您有一个包含名为DateToDisplayAsToday的DateTime字段的模型类,并且该模型可以在App.XAML中访问,那么您将希望在App.XAML.cs 中执行以下操作

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        // Application_Launching fires when the app starts up.
        // retrieve any data you persisted the last time the app exited.
        // Assumes you have a local instance of your model class called model.
        model = new model(); 
    }
    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        // Application_Activated fires when you return to the foreground.
        // retrieve any data you persisted in the Application_Deactivated
        // and then you can set the current DateTime
        model.DateToDisplayAsToday = DateTime.Now;
    }
    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
        // persist an data you don't want to lose during tombstoning
    }
    private void Application_Closing(object sender, ClosingEventArgs e)
    {
        // persist any data you want to keep between separate executions of the app
    }

最新更新