C
C#12mo ago
Alix

await Shell.Current.GoToAsync($"///MainPage"); not working

When i try to await Shell.Current.GoToAsync($"///MainPage"); I am getting System.NullReferenceException: 'Object reference not set to an instance of an object.' Microsoft.Maui.Controls.Shell.Current.get returned null.
1 Reply
Alix
AlixOP12mo ago
this app.xaml.cs
c#
using MauiInvoiceApplication.Pages;

namespace MauiInvoiceApplication
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new NavigationPage(new LoginPage());
}
}
}
c#
using MauiInvoiceApplication.Pages;

namespace MauiInvoiceApplication
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new NavigationPage(new LoginPage());
}
}
}
and this is my appshell.xaml
c#
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiInvoiceApplication.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiInvoiceApplication"
xmlns:pages="clr-namespace:MauiInvoiceApplication.Pages"
Shell.FlyoutBehavior="Disabled">

<ShellContent Title="Home" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />

</Shell>
c#
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiInvoiceApplication.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiInvoiceApplication"
xmlns:pages="clr-namespace:MauiInvoiceApplication.Pages"
Shell.FlyoutBehavior="Disabled">

<ShellContent Title="Home" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />

</Shell>
c#
private async void OnLoginSuccess()
{
Debug.WriteLine("Before navigation");
await Shell.Current.GoToAsync($"///MainPage");
Debug.WriteLine("After navigation");
}
c#
private async void OnLoginSuccess()
{
Debug.WriteLine("Before navigation");
await Shell.Current.GoToAsync($"///MainPage");
Debug.WriteLine("After navigation");
}
someone? ??????
Want results from more Discord servers?
Add your server