xamarin导航登录管理



在我制作的选项卡项目的入口,我希望登录页面首先出现,然后我希望项目打开。我试了很多方法;

Navigation.PushAsync(new Page1());

问题;标签栏不显示

Routing.RegisterRoute("Page1", typeof(Page1));

问题;

什么也没有发生编码;

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>

我试了很多方法,希望你能帮我解决这个问题。

有两种方法可以做到这一点。


在AppShell中包含LoginPage

  1. App中设置AppShellMainPage

  2. 在AppShell中放置两个Tabbar,并将LoginPage放在HomePage之前,并为两个Tabbar设置不同的Route

    <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>
    
  3. 登录时呼叫await Shell.Current.GoToAsync("//Home");,退出时呼叫await Shell.Current.GoToAsync("//Login");

不要在AppShell中包含LoginPage

  1. 先将LoginPage设置为App中的MainPage
  2. 登录时呼叫MainPage = new AppShell();,退出时呼叫MainPage = new LoginPage();

最新更新