c# - 在选项卡导航中打开新页面

标签 c# xaml xamarin navigation tabbedpage

我正在使用选项卡导航并使用一个页面,并且想要打开一个新页面。

在我的 app.xaml.cs 中,我创建导航页面:

public App()
{
    InitializeComponent();
    MainPage = new NavigationPage(new RootPage());
}

在 RootPage 中,我填写导航:

public RootPage()
{
        NavigationPage.SetHasNavigationBar(this, false);

        Children.Add(new TestPage1
        {
            Title = "TestPage1"
        });

        Children.Add(new TestPage2
        {
            Title = "TestPage2"
        });
        Children.Add(new TestPage3
        {
            Title = "TestPage3"
        });
}

这种类型的导航已经运行得很好并且看起来很漂亮。 现在我想在 TestPage3 中打开一个新页面: TestPage3.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="DemoApplication.TestPage3">
  <Button x:Name="openSetup"  Clicked="ItemClicked" Text="open Settings"/>
</ContentPage>

TestPage3.xaml.cs:

namespace DemoApplication
{
    public partial class TestPage3 : ContentPage
    {
        public TestPage3()
        {
            InitializeComponent();
        }
        void ItemClicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new TestPage4());
        }
    }
}

这也可以,但看起来不太好。

新内容在原始选项卡导航下方加载,加载后选项卡导航消失 - 因此 Page4 的内容有点跳跃:)

在 soundcloud 等其他应用程序中,它们也会执行相同的操作,但看起来更流畅。

有什么方法可以让选项卡导航在后退导航之间切换得更顺畅吗?

感谢您的帮助:)

最佳答案

如果您想在选项卡内导航,每个选项卡都应该有自己的导航页面。 TabbedPage 本身不应位于 NavigationPage 内。

MainPage = new RootPage();

Children.Add(new NavigationPage(new TestPage3
        {
            Title = "TestPage3"
        }));

关于c# - 在选项卡导航中打开新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40333247/

相关文章:

c# - 测试时间是否是第二天,不包括午夜

c# - 通过 ado.net 插入 DBGeography 类型的正确方法是什么

c# - 具有径向渐变的 WPF 径向进度条

wpf StringFormat 问题

ios - 未调用 GetHeightForHeader 和 GetViewForHeader

c# - 即使 SignalR SelfHost 服务器上的连接未关闭,是否可能会触发 OnDisconnected 事件?

c# - .net 应用程序更新

c# - 无法使用 MVVM 架构将数据绑定(bind)到文本框?

ios - 当 iOS 应用程序在 Xamarin 中作为后台时,如何通知我蓝牙连接?

iphone - 完整的 Xamarin IDE 设置是什么样的?