Prism and Navigation

Hello Guys, I'm having a problem when navigating with Prism.
If I create a NavigationPage and simply call _navigationService.NavigateAsync("nameOfTheNavigationPage"), I'm getting an unhandled exception: "System.InvalidOperationException: Sequence contains no elements".

If I create this Page as a ContentPage, I don't get this error.

Does somebody know a better way of doing this?

In App.xaml.cs, I start the application with NavigationService.NavigateAsync("LoginPage"); but LoginPage is not a NavigationPage.

Answers

  • BrianLagunasBrianLagunas USInsider ✭✭✭✭

    You can't navigate to an empty NavigationPage. When you initially navigate to a navigationPage, you must specify the view to push onto the NavigationPage in your URI. You need something like:

    NavigateAsync("NavigationPage/FirstView")

  • JorgeGironJorgeGiron USMember

    I have a similar problem, i want star first NavigationService.NavigateAsync("NavigationPage/LoginPage") but after i validate the user i want to go to a MasterDetailPage called MainPage i put NavigationService.NavigateAsync("MainPage/NewsPage"), work nice but i don't want that show the back arrow after login (<- Main), i dont want back to login.

  • BrianLagunasBrianLagunas USInsider ✭✭✭✭

    Than you need to perform an absolute navigation. This is done by prefixing your uri with a "/".

    NavigateAsync("/MainPage/NewsPage");

    This will reset your App.MainPage

  • MO35ABMO35AB Member
    edited January 16

    No need to open new question, i ll just ask here
    Having similar problem, but i have Login page => Masterdetailpage that uses A Navigation page as its Detail content.
    I start the app by navigating to : Login page, from there i navigate to /MasterdetailPage/Home.
    if i wanted to make Home and any other page go inside a MasterDetailPage.Detail ( that is the navigation page ), how should i navigate ?

    here is the code :

        <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                          xmlns:prism="http://prismlibrary.com"
                          prism:ViewModelLocator.AutowireViewModel="True"
                          x:Class="MagMovies.Views.MasterPage"
                          xmlns:ext="clr-namespace:MagMovies.Extensions"
                          xmlns:views="clr-namespace:MagMovies.Views">
            <MasterDetailPage.Resources>
               ....
            </MasterDetailPage.Resources>
    
            <MasterDetailPage.Master>
                <ContentPage Title="Menu" Visual="Default">
                    ...
                </ContentPage>
            </MasterDetailPage.Master>
    
            <MasterDetailPage.Detail>
            <!-- help me here -->
                <views:Home></views:Home>
            </MasterDetailPage.Detail>
    
        </MasterDetailPage>
    
        async void UserAuthenticatedAsync()
        {
            if(ValideCredentials)
              {
                        var p = new NavigationParameters();
                        p.Add("user", Username);
                // and here
                        await _navigationService.NavigateAsync("/MasterPage/Home", p);
              }
        }
    
Sign In or Register to comment.