Xamarin表单:同一个应用程序中的多个导航模式

时间:2016-08-10 17:08:18

标签: xaml xamarin xamarin.forms

我们可以在一个应用中使用多种导航模式吗?

在我的app.xaml页面中,我添加了一个函数

void SetUpNavigation()
        {
            var page = FreshPageModelResolver.ResolvePageModel<LaunchPageModel>();
            var navPage = new FreshNavigationContainer(page);
            MainPage = navPage;
        }

但是在用户登录后我想使用主详细信息页面。有办法吗?

1 个答案:

答案 0 :(得分:2)

是。您只需再次设置应用的MainPage即可。在我们的项目中,我们使用一个辅助类,其方法Restart具有以下逻辑:

public static void Restart(View view, NavigationType navtype)
{
    // Reset the mainpage depending on the navigation type
    if (navtype == NavigationType.RestartWithMasterPage)
    {
        Application.Current.MainPage = new MasterPage(view);
    }
    else if (navtype == NavigationType.Restart)
    {
        Application.Current.MainPage = new NavigationPage(view);
    }
    else
    {
        // Just show the page
        Application.Current.MainPage = view;
    }
}

NavigationType是一个枚举:

public enum NavigationType
{
    Normal,
    Restart,
    RestartWithMasterPage
}