0
votes

PROBLEM

Hey hey hey SO.

I have a master detail page app using mvvm prism. Once a user logs into my app they are taken from the login page to the master page. I want to pass navigation params from my login page to the user detail page nested inside my master page. . . but the detail page is nested in the XAML of the master page so having issues properly passing the arguments.

APP STRUCTURE

master-page.xaml nice little ui right here to render the menu and the user page once the user logs in

<MasterDetailPage.Master>
        <pages:HamburgerMenu x:Name="HamburgerMenu" />
    </MasterDetailPage.Master>
    <MasterDetailPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <pages:UserPage x:Name="UserPage" />
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>

app.xaml.cs entry point for the app rendering the LoginPage which is not a part of the menu items or in any way associated with the master detail page it just has a method that will navigate the user to the master detail page

protected override void OnInitialized()
    {
        InitializeComponent();
        MainPage = new LoginPage();
    }

login-page-viewmodel.cs logging in and passing the trying to pass some user info from my database to the master page which has the nested detail page containing the data bound user name field.

public NavigationParameters np = new NavigationParameters();

    // magic code everywhere

    private async void LoginAsync()
        {
            var user = await LoginAttemptAsync(_awsomePassword);

            np.Add("UserName", user.name);

            await _navigationService.NavigateAsync("MasterPage", np);
        }
1

1 Answers

0
votes

I think changing the navigation string to include a NavigationPage and my UserPage fixed it. Waiting for others feedback. Accepting as right answer for now.

BUGGY CODE

login-page-viewmodel.cs

public NavigationParameters np = new NavigationParameters();

    // magic code everywhere

    private async void LoginAsync()
        {
            var user = await LoginAttemptAsync(_awsomePassword);

            np.Add("UserName", user.name);

            await _navigationService.NavigateAsync("MasterPage", np);
        }

FIXED BUT NOT BEST PRACTICE

* When using Prism, you should build up your navigation stack via the URI. This also lets Prism resolve your views so you can inject dependencies into them if necessary )

login-page-viewmodel.cs

public NavigationParameters np = new NavigationParameters();

    // magic code everywhere

    private async void LoginAsync()
        {
            var user = await LoginAttemptAsync(_awsomePassword);

            np.Add("UserName", user.name);

            await _navigationService.NavigateAsync("MasterPage/Navigation/UserPage", np);
        }

Waiting for feedback from others.