In your application there may be many pages and you will come across requirement to navigate between pages. Windows Phone navigation model allows you to navigate between pages. Windows Phone navigation model is same as web based page navigation model. Even though name suggests in Windows Phone, pages are not windows. In your application, you can navigate between many pages and Windows Phone operating system stores those pages on stack. At any given time you have navigation history stored in the page stack. Windows phone operating system pushes all the pages on the stack and popped out pages with back key. When only one page left on page stack on clicking of hardware back button application gets terminated.
Page stack can be understand with below diagram,
You navigated from Page 1 to Page2 then page stack will be as below,
You navigated from Page2 to Page3. Now Page 3 has been pushed to Page Stack.
On Page 3 you pressed 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 start page of the application. And only one page is left on the Page Stack. Now if you press hardware back button you will come out of the application.
You can iterate the Page Stack by calling BackStack property of NavigationService class.
BackStack property is having only getter and not setter. So you can read all the pages from the stack but cannot manipulate that.
You can read Uri of all the pages in PageStack as below,
In this way you can work with Page Stack in Windows Phone. I hope this post is useful. Thanks for reading.
Follow @debug_mode
Leave a comment