【问题标题】:Xamarin Forms navigation page back to tab out of tabbed contextXamarin Forms 导航页回到选项卡式上下文之外的选项卡
【发布时间】:2016-03-12 14:01:46
【问题描述】:

我在共享 Xamarin.Forms 应用的 App 类中创建了一个主页,如下所示:

public App()
{
    // The root page of your application
    MainPage = new NavigationPage(new MainPage());
}

在该主页中,我将其设置为选项卡并创建了两个子页面:

public partial class MainPage : TabbedPage
{
    public MainPage()
    {
        InitializeComponent ();
        this.Children.Add(new FirstPage());
        this.Children.Add(new SecondPage());
    }
}

FirstPage 有一个点击处理程序,可将您发送到 ThirdPage:

TheButton.Clicked += async (object sender, EventArgs e) => {
                await Navigation.PushAsync(new ThirdPage());
};

正如预期的那样,第三页有一个后退按钮,但是当我单击它时,它会将我返回到标签页上下文之外的 FirstPage。换句话说,我不是回到标签页的子页面,而是没有办法回到标签页的单个子页面。

我是否忽略了一些明显的东西?

【问题讨论】:

  • 您的“FirstPage”是 NavigationPage 还是只是 ContentPage?

标签: xamarin.forms


【解决方案1】:

从您的主页中删除导航页面。

public App()
{
    // The root page of your application
    MainPage = new MainPage();
}

将导航页面添加到您的两个子页面。

public partial class MainPage : TabbedPage
{
    public MainPage()
    {
        InitializeComponent ();
        this.Children.Add(new NavigationPage(new FirstPage())
        {
            Title = "First Page", 
            Icon = "FirstIcon.png" 
        });
        this.Children.Add(new NavigationPage(new SecondPage())
        {
            Title = "Schedule", 
            Icon = "Schedule.png" 
        });
    }
}

更多信息参考:https://www.syntaxismyui.com/xamarin-forms-tabbedpage-navigation-recipe/

【讨论】:

  • 这不适用于 Android。从 ThirdPage 中仍然可以看到这些选项卡。
  • 当你Navigation.PopToRootAsync();时会发生什么?
猜你喜欢
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 1970-01-01
  • 1970-01-01
  • 2022-06-17
  • 2017-10-11
相关资源
最近更新 更多