I have a simple .NET MAUI application and am trying to implement a login page. The goal is nothing more than to show the login page and when the user submits name and password it will go to a view model that will then pass the user along to MainPage. This works, but when it gets to MainPage there are no tabs. My Appshell.xaml looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<ShellItem>
<ShellContent ContentTemplate="{DataTemplate view:Login}" />
</ShellItem>
<TabBar >
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Icon="icon_home" />
<ShellContent
Title="About"
ContentTemplate="{DataTemplate local:About}"
Icon="icon_about" />
</TabBar>
Is there an obvious solution to this issue?
Here is one way to solve this:
App.xaml.cs
, there is a line MainPage = new AppShell();
. Replace this with MainPage = new Login();
.Application.Current.MainPage = new AppShell();
- the line that was originally in App.xaml.cs.NOTE: I am NOT recommending frequently calling "new AppShell()". But for Login, it is fine to delay that call until after Login succeeds.
See also H.A.H.'s answer, which shows an alternative approach, that does not involve directly changing MainPage
. I have not tested that answer myself.