One of the new features in Silverlight 3 is providing an application navigation framework via the Frame and Page controls in the APIs. If you saw my guide to Silverlight 3, you may have seen the section on navigation which describes the functionality and as well has a link to a video tutorial about it.

I wanted to augment that tutorial with some additional information about URI routing, which I think is one of the great features of the framework. You see typically your UriMapper might have a 1:1 mapping and look something like this (note in my sample here I’m putting this in App.xaml, but the model may change in the future of where you can/should place UriMapper):

But what if you still wanted to provide friendlier routes, obfuscate the physical location of the view, but handle the default scenario? You can as long as you follow your own naming conventions. Take for instance if we contain all our pages in a folder called Views in our application. We could then map our routes like this:

1: ...

2:<navcore:UriMapperx:Key="uriMapper">

3:<navcore:UriMappingUri="{}{page}"MappedUri="/Views/{page}.xaml"/>

4:</navcore:UriMapper>

5: ...

You could also follow some naming conventions if you wanted to make sure you limited it to only pages or something so you require the view page to be named SomethingPage.xaml and then can have a route like:

A request to About-Us, History or About would navigate to /Views/AboutPage.xaml regardless. This provides you some flexibility and granularity in your implementation and also provides additional SEO points for your content.

I really like the UriMapper in the navigation framework and have been lobbying to change the default templates Visual Studio spits out to use the UriMapper by default. It provides you with a cleaner (and perhaps shorter) URI as well as obfuscates your “code” from your URI logic. Be sure to check out the video if you aren’t familiar with the framework at all.

I hope this helps and would love to know what you think about the navigation framework?