0

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

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

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

阿尔法

4

2 回答 2

3

自从我进行任何 WP7 开发以来已经有一段时间了,但我确信在重新激活应用程序时会引发一个事件 - 你不能只是查询DateTime.NowDateTime.Today此时?

编辑:查看文档,我认为您需要LaunchingActivated事件。(Launching这样您即使在初次启动时也可以检查时间;Activated在休眠后重新激活。)

于 2012-01-20T07:55:27.910 回答
2

假设您有一个模型类,其中包含一个名为 的 DateTime 字段DateToDisplayAsToday,并且该模型可在 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
    }
于 2012-01-20T08:40:47.350 回答