Shell.Current.GoToAsync to xct:Popup restuls with error System.NullReferenceException

AG 491 Reputation points
2021-07-03T07:42:32.127+00:00

Hi,
I would like to display Popup with xamarin community toolkit Popup so but when trying to navigate to it using Shell I am receiving the error "System.NullReferenceException Message=Object reference not set to an instance of an object."

My Popup XAML Code and Code behind for AddAreaPopup

<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="Restuco_Tables.Views.AddAreaPopup"
           Shell.PresentationMode="ModalAnimated"
             Size="300, 300"
             >

    <StackLayout>
        <Label Text="This is a Popup!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
    </StackLayout>

</xct:Popup>


[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class AddAreaPopup : Popup
    {
        public AddAreaPopup()
        {
            InitializeComponent();
        }
    }

I have registered Routing in AppShell

Routing.RegisterRoute(nameof(AddAreaPopup), typeof(AddAreaPopup));

My call to the Popup using Shell

private async void tbiNewArea_Clicked(object sender, EventArgs e)
{
    await Shell.Current.GoToAsync("/AddAreaPopup");
}

Thanks for any help,
AG

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,313 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-07-05T07:08:46.703+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    The Popup view is not type of Page, it cannot be used in the navigation method. To show the popup, try using the Navigation.ShowPopup method.

       private async void Button_Clicked(object sender, EventArgs e)  
       {  
           Navigation.ShowPopup(new AddAreaPopup());  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful