从TabbedPage导航到ContentPage

时间:2017-06-11 21:15:17

标签: xamarin navigation xamarin.forms

我有一个带有三个标签的TabbedPage,这是我的主页面。在其中一个选项卡中,我有一个ListView,在单击ListView中的Item时,我想导航到一个新的页面。

我可以导航到新页面,但页面会显示在选项卡中。我不希望页面在选项卡中,并且应该打开整个屏幕的新页面。

这是我在其中一个标签中的listView itemSelected方法。

如何让DocketDetail页面占据整个屏幕。

我试过把它作为主页'哪个

App.Current.MainPage = new NavigationPage(new DocketDetail());

但是这样做我无法回到TabbedPage。

请建议

  lvLiveDockets.ItemSelected += (object sender, SelectedItemChangedEventArgs e) =>
            {
                if (e.SelectedItem == null)
                {
                    DisplayAlert("Item DeSelected", e.SelectedItem.ToString(), "Ok");
                    return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
                }
                else
                {
                    DisplayAlert("Item Selected", e.SelectedItem.ToString(), "Ok");
                    this.Navigation.PushAsync(new DocketDetail());
                }

                //((ListView)sender).SelectedItem = null; //uncomment line if you want to disable the visual selection state.
            };

我的App.Xaml.cs

  MainPage = new TabbedPage
            {
                Children =
                {
                    new NavigationPage(new PendingDockets())
                    {
                        Title = "Pending Dockets",
                        Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                    },
                    new NavigationPage(new LiveDockets())
                    {
                        Title = "Live Dockets",
                        Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                    },
                    new NavigationPage(new ArchiveDockets())
                    {
                        Title = "Archive Dockets",
                        Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                    },
                }
            };`

2 个答案:

答案 0 :(得分:0)

您必须将TabbedPage放在导航堆栈中(我认为是根页面)

Application.Current.MainPage = new NavigationPage(new Tabpage());

当你在listview中选择你的项目时,你应该推新页面

Navigation.PushAsync(new DocketDetail());

我希望能理解你的问题

  lvLiveDockets.ItemSelected += (object sender, SelectedItemChangedEventArgs e) =>
            {
                if (e.SelectedItem == null)
                {
                    DisplayAlert("Item DeSelected", e.SelectedItem.ToString(), "Ok");
                    return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
                }
                else
                {
                    DisplayAlert("Item Selected", e.SelectedItem.ToString(), "Ok");
                    Application.Current.MainPage = new DocketDetail();
                }

                //((ListView)sender).SelectedItem = null; //uncomment line if you want to disable the visual selection state.
            };

答案 1 :(得分:0)

您的App.cs可以更改为:

MainPage = new NavigationPage(new TabbedPage()
        {
            Children =
            {
                new PendingDockets()
                {
                    Title = "Pending Dockets",
                    Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                },
                new LiveDockets()
                {
                    Title = "Live Dockets",
                    Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                },
                new ArchiveDockets()
                {
                    Title = "Archive Dockets",
                    Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                },
            }
        });