Multi-page Windows Phone Application
Unlike a desktop application, a smartphone app with its limited real estate does not have the luxury of menus, ribbons, tabs to choose different switch to different windows or pages. One may think switching to a new page is as simple as opening a new page. The key question is: who opens the new page. The original page cannot be the parent owning the new page because you could have the situation that an instance of page A owns an instance of page B which then owns an instance of page A, etc. The pages will stack up.
The key concept of multi-page Silverlight app is maintaining a container that can host different pages. For desktop and web Silverlight app, the container page is usually derived from UserControl. If Visual Studio is used to create a Windows Phone project automatically, App class needs to be modified to use the container instead of MainPage as its VisualRoot. Jesse Liberty has a succinct video explaining this very well.
Phone 7 Silverlight app uses the same mode, but has a container – an instance of PhoneApplicationFrame – by default, so developers do not need to worry about containers. They only need to focus on the contents (instances of PhoneApplicationPage) hosed by the container. From a developer’s point of view, Phone 7 apps’ navigation paradigm is almost identical to that of Web browsers. As any web developer knows, navigation among pages is intuitive and straightforward; the only possible challenge is how to keep the current state (i.e. values of various variables among different pages). Switching to another page is as easy as following:
this.NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
One can even add a query string as used widely in web page navigations like the following:
this.NavigationService.Navigate(new Uri("/AnotherPage.xaml?parmeter1=value1¶meter2=value2", UriKind.Relative));