Page Stack in Windows Phone
In your application there may be many pages and you will encounter a requirement to navigate among pages. The Windows Phone navigation model allows you to navigate among pages. The Windows Phone navigation model is the same as the web based page navigation model. Even though the name suggests Windows Phone, pages are not windows. In your application, you can navigate between many pages and the Windows Phone operating system stores those pages in a stack. At any given time you have a navigation history stored in the page stack. The Windows Phone operating system pushes all the pages on the stack and pop pages back out with the back key. When only one page is left on the page stack, when the hardware back button is clicked, the application is terminated.
The Page stack can be understood with the following diagram. If you navigated from Page 1 to Page 2 then the page stack will be as below.
You navigated from Page2 to Page3. Now Page 3 has been pushed into the Page Stack.
On Page 3 you pressed the hardware back button so Page 3 has been popped out from the Page Stack.
Now on Page 2 you pressed hardware back button so Page 2 has been popped out from the Page Stack.
In last you have navigated back to the start page of the application. And only one page is left on the Page Stack. Now if you press the hardware back button you will exit from the application.
You can iterate the Page Stack by calling the BackStack property of the NavigationService class.
The BackStack property has only a getter and not a setter. So you can read all the pages from the stack but cannot manipulate it.
You can read Uri of all the pages in PageStack as below.
In this way you can work with the Page Stack in Windows Phone. I hope this post is useful. Thanks for reading.