Shell Navigation using query parameters and a Dictionary

Ronald Rex 1,666 Reputation points
2023-05-22T19:25:42.8333333+00:00

Hi Friends,

I have asked this question before, but I should have been a little more detail. Let me begin with the code that was shared with me by someone that was very helpful...

But my question has a few caveats, meaning that the page that I am using in the Shell.Current.GoToAsync is a TabbedPage that has all of the pages related to the that particular functionality of the app. So, again I am not navigating to a ContentPage but a TabbedPage. i.e. await Shell.Current.GoToAsync($"{nameof(PayerEditView)}", navigationParameter); All page(s) reference the same ViewModel so I want to set the navigationParameter in the constructor of the viewmodel. I would greatly appreciate any ideas on how I would achieve this. Thanks !!!

private async void letsseeifthisworks(object sender, EventArgs e)
    {
        MenuFlyoutItem mfi=(MenuFlyoutItem )sender;
        
        
        var navigationParameter = new Dictionary<string, object>
        {
            {"theTeamId",0}
        };
        await Shell.Current.GoToAsync($"{nameof(TeamsPage)}", navigationParameter);

    }

Developer technologies .NET .NET MAUI
Developer technologies C#
{count} votes

Accepted answer
  1. Anonymous
    2023-05-24T02:25:24.0633333+00:00

    Hello,

    If you want to get the transferred value in the View Model, it is recommended way to implement IQueryAttributable interface, get the value by ApplyQueryAttributes method in the ViewModel.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.