0

WP7.5でアプリが非アクティブ状態から戻ったときに日時を更新できるかどうか知りたいのですが。私のアプリは基本的にカレンダータイプで、アプリが起動すると当日が強調表示されます。

したがって、アプリを起動してからスタートボタンを押すと、アプリは非アクティブ状態になり、設定に移動してタイムゾーンを変更します。当然、日付と時刻が変更されてからアプリに戻ると、古い日付が保持されます。 。

例えば。現在の日付が20で、日付が19のタイムゾーンを変更するとします。理想的には、アプリで19を強調表示する必要がありますが、そうではありません。アプリが非アクティブ化される前になり、すべての状態が保存され、戻ったときに同じデータが読み込まれると思います。とにかく日時を更新できますか?

アルファ

4

2 に答える 2

3

WP7の開発を行ってからしばらく経ちますが、アプリが再アクティブ化されたときにイベントが発生することは間違いありません。クエリを実行するだけでいいのではないでしょうDateTime.NowDateTime.Today

編集:ドキュメントを見ると、 LaunchingイベントとActivatedイベントが必要だと思います。(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 に答える