简体   繁体   中英

In Prism 7 for Xamarin Forms, is there a way to get prior page in OnNavigatedTo handler

New to using Prism in Xamarin Forms: INavigationAware gives me the OnNavigatedTo handler. I want different behavior in this form depending on where we are navigating from. Is there a way to get the prior page?

Specifically I have page A that opens page B (modal) if a certain condition is true. However, if the back button is hit from page B, returning me to Page A, I don't want to open page B again. Rather, I want to go back to the prior page beneath Page A on the navigation stack.

Well passing the Page would be in direct violation of MVVM design, as your ViewModel should have no direct clue about the associated View. That said all of the INavigationAware methods use NavigationParameters which means that you can pass some value that you can check for similar to the following:

NavigationService.NavigateAsync("ModalA", new NavigationParameters {{"reason", "foo"}});

public void OnNavigatedTo(INavigationParameters navigationParameters)
{
    switch(navigationParameters.GetValue<string>("reason"))
    {
        case "foo":
            // Do Foo
            break;
        case "bar":
            // Do Bar
            break;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM