0

この方法でページ ナビゲーションを設計したとします。

P(1) -> P(2) に移動 -> P(3) に移動し、P(3) で、ユーザーはホーム ボタン (Microsoft ボタン) をクリックします。

a) アプリの再起動時に p(3) に戻るにはどうすればよいですか?

ありがとう

- - アップデート

このイベントで何をする必要がありますか?

protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Window に既にコンテンツがある場合は、アプリの初期化を繰り返さないでください。
            // ウィンドウがアクティブであることを確認します

            if (rootFrame == null)
            {
                // ナビゲーション コンテキストとして機能するフレームを作成し、最初のページに移動します

                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 以前に中断されたアプリケーションから状態をロードする
                }

                // フレームを現在の Window に配置します

                Window.Current.Content = rootFrame;

            }

            if (rootFrame.Content == null)
            {
                // ナビゲーション スタックが復元されていない場合は、最初のページに移動し、
                // 必要な情報をナビゲーションとして渡すことにより、新しいページを構成します
                // パラメータ

                if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
                {
                    throw new Exception("初期ページの作成に失敗しました");
                }
            }

            // 現在のウィンドウがアクティブであることを確認します
            Window.Current.Activate();
        }



4

1 に答える 1

1

OnNavigatedToローカル設定を使用して、各ページのイベントで最後に開いたページを保存できます。

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    ApplicationData.Current.LocalSettings.Values["LastPage"] = this.GetType().ToString();
}

OnLaunched(..)App.xaml.cs のイベントの後、最後に開いたページを確認します。それによると、ナビゲートできます。

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();

        if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //TODO: Load state from previously suspended application
        }

        // Place the frame in the current Window
        Window.Current.Content = rootFrame;
    }

    if (rootFrame.Content == null)
    {
        // When the navigation stack isn't restored navigate to the first page,
        // configuring the new page by passing required information as a navigation
        // parameter

        if (ApplicationData.Current.LocalSettings.Values["LastPage"] != null)
        {
            Type t = Type.GetType((string)ApplicationData.Current.LocalSettings.Values["LastPage"]);
            if (!rootFrame.Navigate(t, args.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }
        }

        else
        {
            if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }
        }
    }
    // Ensure the current window is active
    Window.Current.Activate();
}
于 2013-09-12T05:29:50.630 に答える