0

In Windows phone 8 app, instead of always opening the application with same PhoneApplicationPage, I need to switch the initial view. i.e. Home page if settings already exists and settings page if the user opens the app for the first time.

How should I go about it?

Currently the way I adopted is :

Made Default task empty in WMAppManifest.xml

<DefaultTask Name="_default"  />

Decided which page to move to in Application_Launching event handler.

private void Application_Launching(object sender, LaunchingEventArgs e)
{
    if (SettingFileExists())
        RootFrame.Navigate(new Uri("Home.xaml", UriKind.Relative));
    else
        RootFrame.Navigate(new Uri("Settings.xaml", UriKind.Relative));
}

Is this the best way to approach this scenario? Is there any potential issue with my code?

4

1 に答える 1

1

これを行うにはさまざまな方法があり、「最善の」方法はありません。

私の個人的な好みはUriMapper、起動時にリダイレクトを行うカスタムを使用することです。
例えば

  • Navigation スタートアップ Uri を、存在しない特別なものに設定します。例: 「スタートアップ」
  • カスタム UriMapper を設定します。

        RootFrame.UriMapper = new MyUriMapper();
    
  • 次に、UriMapper で特別な uri をチェックし、適切なアクションを実行します。

    public class MyUriMapper : UriMapperBase
    {
        public override Uri MapUri(Uri uri)
        {
            if (uri.OriginalString == "/StartUp")
            {
                if (!this.dataOperations.IsLoggedIn())
                {
                    return Login.Path;
                }
                else
                {
                    return Main.Path;
                }
            }
    
            return uri;
        }
    }
    
于 2013-11-06T13:37:01.287 に答える