Forum Xamarin.Forms

Shell showing Modal pages

RogerSchmidlinRogerSchmidlin CHUniversity ✭✭✭

I would like to use modal pages the same as I use GoToAsync("modalpage?parameter=somevalue") navigation. Is this possible?

Tagged:

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    I would like to use modal pages the same as I use GoToAsync("modalpage?parameter=somevalue") navigation.

    It is impossible .

    GoToAsync("modalpage?parameter=somevalue") equals to Navigation.PushAsync(new modalpage());

    The default way is taking Hierarchical navigation not Modal Pages.

    If you want it , don't take the route way , use Navigation.PushModalAsync(new modalpage()); in code behind .

  • RogerSchmidlinRogerSchmidlin CHUniversity ✭✭✭

    @ColeX the you lose the nice feature of passing parameters. I don't want to use two different kind of navigation systems. It's nice to register all the pages in one place and then just navigate with a path and pass parameters. I also want that with Modal pages. Maybe Shell.Current.PushModal

  • AhmedAlejoAhmedAlejo USMember ✭✭
    edited March 10

    Hi @RogerSchmidlin

    A bit late to the party, but for the reference sake.

    you can accomplish your need by using the following extension method via Routing.GetOrCreateContent.

    public static Task GoToModalAsync(this Shell shell ,string route)
    {
        var page = Routing.GetOrCreateContent(route) as Page;
    
        if (page is null) return Task.CompletedTask;
    
        return shell.Navigation.PushModalAsync(page);
    }
    
    then
    await Shell.Current.GoToModalAsync("modalpage?parameter=somevalue");
    

    works as expected.

  • DidsDids FIMember ✭✭

    @AhmedAlejo said:
    Hi @RogerSchmidlin

    A bit late to the party, but for the reference sake.

    you can accomplish your need by using the following extension method via Routing.GetOrCreateContent.

    public static Task GoToModalAsync(this Shell shell ,string route)
    {
        var page = Routing.GetOrCreateContent(route) as Page;
    
        if (page is null) return Task.CompletedTask;
    
        return shell.Navigation.PushModalAsync(page);
    }
    
    then
    await Shell.Current.GoToModalAsync("modalpage?parameter=somevalue");
    

    works as expected.

    This only seems to work without parameters. With parameters, it seems to always return null, otherwise it seems to work.

Sign In or Register to comment.