0
votes

I have a simple Xamarin forms based application which submits an application to a service, upon which I want to clear the navigation stack, so that a new application can be entered. I'm using the MVVM Light framework but the built in navigation service has no method clear the stack.

I know this is possible with out of the box Xamarin using Navigation.RemovePage, but not sure how to implement this within MVVM Lights navigation service.

I have the following in the NavigateTo method using parameter as an indicator to clear the stack:

if (parameter == null)
{
    foreach (var pageList in _navigation.Pages)
    {
        //Remove from navigation stack                                   
    }
}   

I was hoping I could fire something from here to clear the stack so that the pages are refreshed, or is there a better way of doing it, possibly from the viewmodel directly?

Thanks

1
If your _navigation field is a Xamarin.Forms.NavigationPage, you could just use _navigation.PopToRootAsync() - Frauke
That does indeed remove everything from the stack however my forms are still showing the previous application data, as if they were cached? - trebor74

1 Answers

0
votes

In case it helps anyone, using MVVMLight, you can use :

SimpleIoc.Default.Unregister<ViewModel>();

This completely removes the view model/bindings from cache and all previous instances.

I found just popping from the stack, (using Application.Current.MainPage.Navigation.PopAsync();) didn't clear the model data, just the navigation stack.