我正在使用选项卡导航并使用一个页面,并且想要打开一个新页面。
在我的 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/