登录后如何在 Xamarin 中重定向有关 TabbedPage 的信息

How to redirect after login about TabbedPage in Xamarin

我有:

  1. MainView.xaml

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         BackgroundColor="#fff"
         ...
      >
      <views:Page1 Title="Page1" IconImageSource="homeicon" BackgroundColor="#fff"/>
      <views:Page2 Title="Page2" IconImageSource="order" BackgroundColor="#fff"/>
      <views:Page3 Title="Page3" IconImageSource="ads" BackgroundColor="#fff"/>
      <views:Page4 Title="Page4" IconImageSource="usericon" BackgroundColor="#fff"/>
    </TabbedPage>
    

我有 1 个登录页面。登录后,您将被重定向到第4页。

我使用:App.Current.MainPage = new NavigationPage(new Page4())

if (response.IsSuccessStatusCode)
{
   var responseBody = await response.Content.ReadAsStringAsync();
   App.Current.MainPage = new Page4();
}  

但是我没有显示 TabbedPage

如何显示下面的标签列表。请帮我解决问题。谢谢

更新 我试试

On Log in => App.Current.MainPage = new MainView();

Log Out => App.Current.MainPage = new LoginPage();

还是不行

当您更改 App.Current.MainPage 时,您会更改应用程序的 MainPage 以放置其中的任何内容,以便该页面是应用程序中唯一存在的页面。尝试在那里设置您的标签页,您将拥有标签页作为 'MainPage'。 现在您的 MainPage 是选项卡式页面,您可以使用以下代码(在 TabbedPage 内)更改显示的页面:

CurrentPage = Children[3]; // 0, 1, 2, 3 

您会注意到您可以在附加到 TabbedPage 的任何 ContentPage 之间切换

现在可以使用(App.Current.MainPage 作为 TabbedPage)访问 MainPage,因此很容易从其他地方更改显示的页面

将您的页面放在导航页面中。这应该可以帮助您修复它。

更新:

在MainView.xaml.cs中放这个

public MainView(int index)
{
InitializeComponent();
SetPage(index);
}

void SetPage(int index) { CurrentPage=Children[index]; }

登录后,执行此操作

App.Current.MainPage = new NavigationPage(new MainView(3))