'How to dismiss multiple (all) modals at once?

Is there a way to dismiss multiple modals or only one by one like this: Navigation.ModalPopAsync()?



Solution 1:[1]

I've actually written something to pop all modals.

It works by first figuring out how many modals are active then by popping them.

And yes, as Rohit Vipin Mathews mentioned in his answer, PopModalAsync(false); will remove the animation.

// Get number of modals on the Navigation Stack
int numModals = Application.Current.MainPage.Navigation.ModalStack.Count;

// Pop each modal in the stack
for (int currModal = 0; currModal < numModals; currModal++)
{
    await Application.Current.MainPage.Navigation.PopModalAsync();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1