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:

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.

Bind the mappings with the UriMapper instance and set RootFrame.UriMapper to the UriMapper instance.

Call the method right after the RootFrame have been instantiated – typically in InitializePhoneApplication.

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.

Yesterday Scott Guthrie announced a beta of Silverlight 5, which will be available in Q2 of 2011 and released in 2011.

Silverlight 5 builds on the foundation of Silverlight 4 for building business applications, premium media applications and applications that reach beyond the browser. Silverlight 5 introduces more than 40 new features, including support for running Silverlight applications with desktop features in the browser, dramatic video quality and performance improvements, and features that improve developer productivity. The Silverlight 5 beta will be available sometime in Q2 of 2011.