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

发布于 2024-12-28 06:48:45 字数 305 浏览 1 评论 0原文

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

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

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

阿尔法

i would like to know if it is possible to refresh date time when the app returns from a deactivated state in WP7.5. My app is basically a calendar type and when the app starts the current day is highlighted.

So if i start the app, then press the start button, my app goes to deactivated state, then go to settings and change the time zone, naturally the date and time may change and then come back to my app, it retains the old date.

eg.
Suppose current date is 20 and we change the timezone where the date is 19, ideally my app should highlight 19, but it does not. I assume that its becomes before the app goes into deactivated state, it stores all the states and when it returns, it loads the same data. Is there anyway i could refresh the datetime?

Alfah

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流云如水 2025-01-04 06:48:45

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

编辑:查看文档,我认为您想要 启动已激活事件。 (启动,以便您即使在首次启动时也能检查时间;激活,用于在休眠后重新激活。)

It's been a while since I've done any WP7 development, but I'm sure there's an event raised when the app is reactivated - can't you just query DateTime.Now or DateTime.Today at that point?

EDIT: Looking at the docs, I think you want the Launching and Activated events. (Launching so that you check the time even on the initial launch; Activated for reactivation after becoming dormant.)

沫尐诺 2025-01-04 06:48:45

假设您有一个模型类,其中包含名为 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
    }

Assuming that you have a model class that contains a DateTime field called DateToDisplayAsToday, and that model is accessible within App.XAML, you will want to to the following in 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
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文