UriMapping for WP7

15 Dec

UriMapping for Silverlight is pretty straight forward and if you use the Silverlight Navigation template you get it all from the template. WP7 contains many of the same features – it’s just not that obvious.

By default a WP7 app navigate using a PhoneApplicationFrame. PhoneApplicationFrame inherits from Frame – the control used in Silverlight. The PhoneApplicationFrame control is exposed as a property named RootFrame in App.xaml.cs.

To enable UriMapping in WP7 from the code you need to follow a few simple steps:

  1. Create a new method (in App.xaml.cs) that will set the UriMappings you need. In the method you need to make a new instance of UriMapper and for each mapping you wish to create you need to instantiate a new UriMapping specifying the Uri and MappedUri.
  2. Bind the mappings with the UriMapper instance and set RootFrame.UriMapper to the UriMapper instance.
  3. Call the method right after the RootFrame have been instantiated – typically in InitializePhoneApplication.
  4. Modify the existing start page in WMAppManifest.xml to make it fit your mappings.

In the sample below I have added two mappings; a default mapping and a mapping for a detailsview.

2010-12-15_152217

To use your mappings simply call your pages using a relative Uri:

2010-12-15_153430

You can download a demo here.

by xamlgeek
@thomasmartinsen

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: