2

私のアプリケーションは、現在、MainPage.xaml起動時に行きます(ただし、どこに設定されているかわかりません)。

条件によっては別のページから始められるようにしたい。Application_Launching()このコードをページ内に追加できると思いApp.xaml.csます:

NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

ただしNavigationService、App.xaml.cs では使用できません。

次の場合、別のページでアプリケーションを開始するにはどうすればよいfoo == trueですか?

4

3 に答える 3

4

の開始ページの変更App.Xaml.cs:

private void Application_Launching(object sender, LaunchingEventArgs e)
{

        Uri nUri = new Uri("/SecondPage.xaml", UriKind.Relative);
        ((App)Application.Current).RootFrame.Navigate(nUri);

}

Property\WMAppManifest.xmlファイルに静的な起動ページを設定する

<DefaultTask  Name ="_default" NavigationPage="SecondPage.xaml"/>

編集

それを試してみてください:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        Uri nUri = new Uri("/GamePage.xaml", UriKind.Relative);
        RootFrame.Navigate(nUri);
    }

そしてProperty\WMAppManifest.xml明確なNavigationPageで:

<DefaultTask  Name ="_default" NavigationPage=""/>
于 2013-10-03T21:41:59.823 に答える
3

条件に応じて移動する方法は次のとおりです。

App.xaml.cs のコンストラクターに以下を追加します。

RootFrame.Navigating+= RootFrameOnNavigating;

次に、RootFrameOnNavigating を次のように定義します。

    private bool firstNavigation = true;
    private void RootFrameOnNavigating(object sender, NavigatingCancelEventArgs navigatingCancelEventArgs)
    {

        //by defaullt stringOfPageNameSetInWMAppManifest is /MainPage.xaml
        if (firstNavigation && navigatingCancelEventArgs.Uri.ToString().Contains(stringOfPageNameSetInWMAppManifest))
        {
            if (foo == true)
            {
                //Cancel navigation to stringOfPageNameSetInWMAppManifest
                navigatingCancelEventArgs.Cancel = true;

                //Use dispatcher to do the navigation after the current navigation has been canceled
                RootFrame.Dispatcher.BeginInvoke(() =>
                {

                    RootFrame.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
                });
            }
        firstNavigation = false;
    }

もう 1 つの方法は、UriMapper を使用して、特定のページに移動したときにナビゲートされる uri を再定義することです。

于 2013-10-03T22:07:24.390 に答える