Windows Phone remove specific BackStack entry

3.1k views Asked by At

I am trying to remove the specific BackStack entry from NavigationService.BackStack.

I found there is one method to remove back entry i.e. NavigationService.RemoveBackEntry();, but it remove all back entries from stack. So, my question is How to remove specific back entry?

How can I remove the query string from NavigationService.CurrentSource? I want retrieve only Uri without Query String.

Thank you in advance :)

2

There are 2 answers

0
Abhishek On

You can't remove specific back stack entity, because your current stack(current page) can interact with its adjacent stack only, So can remove only its previous stack entity. You need to remove stack at time of NavigateTo() next page.

1
Freeubi On

I can do that with this code. Insert this into a page.Loaded event:

int backstackcounter = this.NavigationService.BackStack.Count();

            for (int i = 0; i < backstackcounter; i++)
            {
               var previousPage = this.NavigationService.BackStack.FirstOrDefault();

                if (previousPage != null && !previousPage.Source.ToString().StartsWith("/LoginPage.xaml"))
                {
                    this.NavigationService.RemoveBackEntry();
                }
            }

The "LoginPage.xaml" is a page that i want to stay in the backstack.