在我做的選項卡式專案的入口處,我希望登錄頁面首先出現,然后我希望專案打開。我嘗試了很多方法;
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>
應用程式.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()
{
}
}
應用程式.xaml
<Application.Resources>
</Application.Resources>
我嘗試了很多方法希望你能幫助我解決它。
uj5u.com熱心網友回復:
有兩種方法可以實作這一點。
將 LoginPage 包含到 AppShell 中
設定
AppShell為.MainPage_AppTabbar在 AppShell 中放置兩個,并放置在LoginPage第一比,并為兩者HomePage設定不同。RouteTabbar<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>await Shell.Current.GoToAsync("//Home");登錄時呼叫,await Shell.Current.GoToAsync("//Login");注銷時呼叫。
不要在 AppShell 中包含 LoginPage
- 設定
LoginPage為最初MainPage。App MainPage = new AppShell();登錄時呼叫,MainPage = new LoginPage();注銷時呼叫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/470492.html
