#WinRT #Win8Dev Page Navigation for #WPDev #WP7Dev

2 Weeks back I attended a session aptly called Windows 8 Development for Windows Phone Developers. The first thing we were told is that.. if you do WPDev you already know what needs to be done. However apart from the idea about Metro and using XAML & C# nothing else is common between the two. My 2 weeks dev tells me that it was as close to the truth as you can get.

Lets look at Page Navigation differences as they have plagued me since last night.

In Windows Phone Dev, you’d use something like this to navigate from Page A to Page B

NavigationService.Navigate(new Uri("/GamePlay.xaml", UriKind.Relative));

In Windows 8 / Windows RT Development we would do

Frame.Navigate(typeof(Gameplay));

Okay now that wasn’t so bad.. in Windows Phone Dev, you navigate to Uri, In Windows 8 Dev you navigate to a type.

How about navigating back the Navigation Stack ?

if(NavigationService.CanGoBack)
    NavigationService.GoBack();

With Windows Phone Dev

if(this.Frame.CanGoBack)
    this.Frame.GoBack();

WindowsPhone NavigationService also exposes a method called RemoveBackEntry. This is used to clear the last entry in the stack and can use used recursively. WinRT provides no such methods.

Now here’s the good part. Windows 8 Metro projects add a class called LayoutAwarePage and it exposes easy methods like GoHome() or GoBack(). Infact Windows 8 Metro pages already bind the back button with GoBack Property. If you want to go home, you just change the binding to GoHome.

Now for the last part.
If you navigate between pages, you can choose to cache pages. That is something new from perspective of a Windows Phone Dev. All you do is set the property on Page class called NavigationCacheMode.
MSDN -

To cache a page, you must set the Page.NavigationCacheMode property to either Enabled or Required. When a page’s NavigationCacheMode property is set to Required, the page is cached regardless of the number of cached pages specified in the CacheSize property. Pages marked as Required don’t count against the CacheSize total.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s