At the entrance of the tabbed project I made, I want the login page to come first, then I want the project to open. I tried many ways;
Navigation.PushAsync(new Page1());
Problem; tabbar doesn't show
Routing.RegisterRoute("Page1", typeof(Page1));
Problem; Nothing happens
Codes;
AppShell.xaml.cs
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute(nameof(page1), typeof(page1));
Routing.RegisterRoute(nameof(page2), typeof(page2));
Routing.RegisterRoute(nameof(page3), typeof(page3));
}
}
AppShell.xaml
<TabBar>
<ShellContent Route="page1" ContentTemplate="{DataTemplate local:page1}" />
<ShellContent Route="page2" ContentTemplate="{DataTemplate local:page2}" />
<ShellContent Route="page1" ContentTemplate="{DataTemplate local:page1}" />
</TabBar>
App.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
App.Current.MainPage = new NavigationPage(new LoginPage());
//MainPage = new NavigationPage(new LoginPage());
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
App.xaml
<Application.Resources>
</Application.Resources>
I tried so many ways hope you can help me solve it.
CodePudding user response:
There are two ways to achieve this .
Include LoginPage into AppShell
Set
AppShell
asMainPage
inApp
.Place Two
Tabbar
in AppShell , and placeLoginPage
first thanHomePage
, and set differentRoute
for the twoTabbar
.<TabBar Route="Login"> <ShellContent ContentTemplate="{DataTemplate local:LoginPage}" /> </TabBar> <TabBar Route="Home"> <ShellContent Title="Menu" Icon="home.png" ContentTemplate="{DataTemplate local:AdminMenuPage}" /> <ShellContent Title="Settings" Icon="settings.png" ContentTemplate="{DataTemplate local:SettingsPage}" /> </TabBar>
Call
await Shell.Current.GoToAsync("//Home");
when login in , Callawait Shell.Current.GoToAsync("//Login");
when login out .
Don't Include LoginPage into AppShell
- Set
LoginPage
asMainPage
inApp
at first. - Call
MainPage = new AppShell();
When login in , CallMainPage = new LoginPage();
when login out .