How do I clear the Navigation stack?

后端 未结 5 1236
无人共我
无人共我 2021-02-18 18:03

I have problem for Navigation in my app. I use xamarin.forms how can clean my navigation stack. No use Pop and push. Can I see my full navigation stack ?

5条回答
  •  难免孤独
    2021-02-18 18:08

    You can try this...

        public void ResetNavigationStack()
        {
            if (_navigation != null && _navigation.NavigationStack.Count() > 0)
            {
                var existingPages = _navigation.NavigationStack.ToList();
                foreach (var page in existingPages)
                {
                    _navigation.RemovePage(page);
                }
            }
        }
    

    and BOOOM!!! that nav stack is cleared brotha!

    Or if you wanna reset the modal stack

        public async Task PopAllModals()
        {
            Page root = null;
    
            if (_navigation.ModalStack.Count() == 0)
                return null;
    
            for (var i = 0; i <= _navigation.ModalStack.Count(); i++)
            {
                root = await _navigation.PopModalAsync(false);
            }
            return root;
        }
    

    And BOOOM! those modals are gone!

提交回复
热议问题