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

Windows phone 7 如何在WP中重新激活应用程序时刷新日期时间,windows-phone-7,datetime,tombstoning,Windows Phone 7,Datetime,Tombstoning,我想知道,当应用程序从WP7.5中的停用状态返回时,是否可以刷新日期时间。我的应用程序基本上是日历类型,当应用程序启动时,会突出显示当天 因此,如果我启动应用程序,然后按开始按钮,我的应用程序将进入停用状态,然后进入设置并更改时区,日期和时间自然可能会更改,然后返回到我的应用程序,它将保留旧日期 例如。 假设当前日期为20,我们更改了日期为19的时区,理想情况下我的应用程序应该突出显示19,但它不会。我假设它在应用程序进入停用状态之前变为,它存储所有状态,当它返回时,加载相同的数据。我可以刷新日

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

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

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


Alfah

我已经有一段时间没有做任何WP7开发了,但是我确信当重新激活应用程序时会引发一个事件-你不能只查询
日期时间。现在
日期时间。今天
在那一点上


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

我已经有一段时间没有做任何WP7开发了,但是我确信当应用程序被重新激活时会引发一个事件-你不能直接查询
DateTime.Now
DateTime.Today


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

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

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

谢谢你,乔恩。问题在于DateTime。Today始终返回应用程序第一次启动的日期(如果应用程序已停用)。除非应用程序退出并重新启动,否则DateTime.Now和DateTime.Today将返回旧的日期。@alfah:这听起来很奇怪-如果您使用
DateTime.Now
它应该始终为您提供当前时间。我相信这不仅仅是给你“最初的时间”-它可能没有注意到时区的变化,不可否认。。。要进行诊断,请在之前和之后检查
TimeZoneInfo.Local
。。。如果这一点正在改变,您可以只使用
DateTime.UtcNow
TimeZoneInfo.Local
.if(dateToDisplay==System.DateTime.Now.Day&&m_monthBuffer[i,j]==m_selectedDate.Month){//do something}我使用了此条件,System.DateTime.Now将在1月20日而不是1月19日给我一个时间,因为我在应用程序处于停用状态时更改了时区。}@阿尔法:那么你有没有按照我的建议检查过
时区信息。本地的
在之前和之后给你提供了什么?是的,我检查过时区信息。本地的,很明显,即使设置中的时区发生了变化,这里也没有发布。。即使在更改后,它仍保持与第一个区域相同的区域。有什么办法可以让你重新振作起来吗?谢谢你,乔恩。问题在于DateTime。Today始终返回应用程序第一次启动的日期(如果应用程序已停用)。除非应用程序退出并重新启动,否则DateTime.Now和DateTime.Today将返回旧的日期。@alfah:这听起来很奇怪-如果您使用
DateTime.Now
它应该始终为您提供当前时间。我相信这不仅仅是给你“最初的时间”-它可能没有注意到时区的变化,不可否认。。。要进行诊断,请在之前和之后检查
TimeZoneInfo.Local
。。。如果这一点正在改变,您可以只使用
DateTime.UtcNow
TimeZoneInfo.Local
.if(dateToDisplay==System.DateTime.Now.Day&&m_monthBuffer[i,j]==m_selectedDate.Month){//do something}我使用了此条件,System.DateTime.Now将在1月20日而不是1月19日给我一个时间,因为我在应用程序处于停用状态时更改了时区。}@阿尔法:那么你有没有按照我的建议检查过
时区信息。本地的
在之前和之后给你提供了什么?是的,我检查过时区信息。本地的,很明显,即使设置中的时区发生了变化,这里也没有发布。。即使在更改后,它仍保持与第一个区域相同的区域。那么,有什么方法可以刷新它吗?显然,我发现,即使更改时区,当应用程序重新激活时,它也不会得到反映。我查过TimeZoneInfo.local。即使在更改后,它仍保持相同的时间:(显然,我发现即使更改了时区,在重新激活应用程序时也不会反映出来。我已经检查了TimeZoneInfo.local。即使更改后,它仍保持相同的时间。)(