英文:
How to change between a ContentPage to a FlyoutPage
问题
I want to develop a mobile application and the first page should be a Login page. When the user has been logged, I want to show a FlyoutPage with different options, but my problem is when I use NavigationPage to change from the login page to the FlyoutPage, the system hides the FlyoutPage menu options and shows the back button.
This is the login page.
.
英文:
I want to develop a mobile application and the first page should be a Login page. When de user has been logged, I want to show a FlyoutPage with differents options, but my problem is when I use NavigationPage to change from the login page to the FlyoutPage the system hides the FlyoutPage menu options and shows the back button.
This is the login page.
.
答案1
得分: 0
你可以使用 AppShell。尝试这样做:
AppShell.xaml
<Shell x:Class="mycompany.AppShell"
xmlns:pages="clr-namespace:mycompany.Pages"
xmlns:mycompany="clr-namespace:mycompany"
x:DataType="mycompany:AppShell"
FlyoutBehavior="Flyout">
<FlyoutItem Title="主页">
<Tab Title="标签1">
<ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
</Tab>
<Tab Title="标签2">
<ShellContent ContentTemplate="{DataTemplate pages:HomePage}"/>
</Tab>
</FlyoutItem>
<FlyoutItem Title="选项1">
<ShellContent ContentTemplate="{DataTemplate pages:ItemPage}"/>
</FlyoutItem>
<FlyoutItem Title="关于">
<ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
</FlyoutItem>
</Shell>
在 AppShell.xaml.cs
public AppShell()
{
InitializeComponent();
// 如果需要,跳转到登录页
Navigation.PushAsync(new LoginPage());
}
在 LoginPage.xaml.cs
public LoginPage()
{
InitializeComponent();
// 隐藏底部标签栏
Shell.SetTabBarIsVisible(this, false);
}
在 LoginPage.xaml 中隐藏顶部导航:
<ContentPage Shell.NavBarIsVisible="false">
</ContentPage>
最后一步是导航回 Shell 标签页,最佳位置是在 LoginPage 的 ViewModel 中,完成登录流程并导航到主屏幕。
Task.Run(async () =>
{
// 导航回主 Shell 页面,包含标签和侧边菜单
await Shell.Current.Navigation.PopToRootAsync();
});
希望对你有所帮助。
英文:
You can use AppShell. Try this:
AppShell.xaml
<Shell x:Class="mycompany.AppShell"
xmlns:pages="clr-namespace:mycompany.Pages"
xmlns:mycompany="clr-namespace:mycompany"
x:DataType="mycompany:AppShell"
FlyoutBehavior="Flyout">
<FlyoutItem Title="HOME">
<Tab Title="tab1">
<ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
</Tab>
<Tab Title="tab2">
<ShellContent ContentTemplate="{DataTemplate pages:HomePage}"/>
</Tab>
</FlyoutItem>
<FlyoutItem Title="item1">
<ShellContent ContentTemplate="{DataTemplate pages:ItemPage}"/>
</FlyoutItem>
<FlyoutItem Title="ABOUT">
<ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
</FlyoutItem>
</Shell>
At AppShell.xaml.cs
public AppShell()
{
InitializeComponent();
//goto login if you want
Navigation.PushAsync(new LoginPage());
}
At LoginPage.xaml.cs
public StartPage()
{
InitializeComponent();
//hide bottom tabs
Shell.SetTabBarIsVisible(this, false);
}
At LoginPage.xaml hide the top navigation:
<ContentPage Shell.NavBarIsVisible="false">
</ContentPage>
The final step is to navigate back to the Shell tab page, the best place would be at the ViewModel of your LoginPage, you have to complete the login process and go to your main screen.
Task.Run(async () =>
{
//go to our main shell page with tabs and flyout menu
await Shell.Current.Navigation.PopToRootAsync();
});
Hope that helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论