Guilherme Waltricke
Guilherme Waltricke

Reputation: 195

Prism for Xamarin.Forms NavigationService OnNavigatedFrom/OnNavigatedTo

we are trying to use OnNavigatedFrom and OnNavigatedTo but the "OnNavigatedTo" is not called when needed

ViewModelOne:

_navigationService.NavigateAsync("ViewModelPageTwo", useModalNavigation: false);

ViewModelTwo:

var parameters = new NavigationParameters()
            {
                {
                    "Pesquisa",
                    TextoPesquisa
                },
                {
                    "DataEnvioInicial",
                    DataEnvioInicio
                },
                {
                    "DataEnvioFim",
                    DataEnvioFim
                },
                {
                    "DataHistoricoInicio",
                    DataHistoricoInicio
                },
                {
                    "DataHistoricoFim",
                    DataHistoricoFim
                },
                {
                    "TodasAsCaixas",
                    PesquisaEmTodasCaixas
                }
            };

            _navigationService.GoBackAsync(parameters);

The problem is that ViewModelOne -> OnNavigatedTo not trigger when GoBackAsync from ViewModelTwo

Upvotes: 0

Views: 1463

Answers (1)

user5420778
user5420778

Reputation:

So what's happening is when you call GoBackAsync, you are actually going back to the TabbedPage, not the actual Tab. For now, you can implement INavigationAware on the actual TabbedPage, and then pass your parameters to the selected Tab's VM in the code-behind. Not optimal, but it will work for now. There is actually a discussion on the GitHub site talking about the various issues when dealing with TabbedPages and it's children during navigation. YOu can follow it here:

https://github.com/PrismLibrary/Prism/issues/650

Upvotes: 1

Related Questions