Page view counter

What’s New In Silverlight 3 – Navigation

As Silverlight moves from providing controls and UX bits to providing a framework for creating entire applications, it becomes more important to have a framework for multi-“page” applications.  Silverlight 3 introduces the Silverlight Navigation Application

SLNav101

This template in Visual Studio creates a series of files that serve as a very flexible and customizable framework for multi-page applications. The unmodified user experience, out of the box, is shown in this live demo, followed by a brief analysis of the code that Visual Studio creates.

(Note that I did modify the size to fit this page.) Visual Studio creates the usual MainPage.xaml/...cs and App.xaml/...cs files but also creates an Assets folder, containing Styles.xaml and a Views folder containing three starter pages:
  • Home.xaml
  • About.xaml
  • ErrorWindow.xaml

Each with its own code-behind.

You’ll notice that if you click on about the page switches, while the frame around the page does not. 

Frame and URI Mapping

I’ll go into the details in an upcoming mini-tutorial and video, but the basic structure is that MainFrame.xaml provides an instance of System.Windows.Controls.Frame  (found in the d System.Windows.Controls.Navigation namespace).  The Frame supports navigation among pages, and also supports passing information to the page to tell it what state it should be in.

Rather than forcing you to provide a full path to the page, the Frame class allows you to request the page you want with an instance of URIMapping, which in turn provides support for parameterized URIs that request a page by mapping parameters to a full URI.

For example, your frame might contain a URIMapping that looks like this:

 

   1: <!-- snippet from the Silverlight Documentation -->
   2: <navigation:Frame.UriMapper>
   3:        <uriMapper:UriMapper>
   4:            <uriMapper:UriMapping 
   5:                Uri="/ProductDetail/{productid}" 
   6:                MappedUri="/Views/ProductDetail.xaml?ProductId={productid}"/>
   7:            <uriMapper:UriMapping 
   8:                Uri="/{pageName}" 
   9:                MappedUri="/Views/{pageName}.xaml"/>
  10:        </uriMapper:UriMapper>
  11:    </navigation:Frame.UriMapper>

You can see that this allows you to bring up a Product Detail page based on the provided ProductID and a second page based on whatever name is provided.

(full details and a complete walk through to come in the forthcoming mini-tutorial and video).

 

 

PreviousMerged Resources

Published Monday, July 27, 2009 12:50 PM by jesseliberty

Comments

# What’s New In Silverlight 3 – Navigation - Jesse Liberty - Silverlight Geek

Thank you for submitting this cool story - Trackback from NewsPeeps

Monday, July 27, 2009 1:27 PM by NewsPeeps

# What's New In Silverlight 3 - Jesse Liberty - Silverlight Geek

Pingback from  What's New In Silverlight 3 - Jesse Liberty - Silverlight Geek

# re: What’s New In Silverlight 3 – Navigation

Could we use MEF to lazy load the User Control or the content of the pages we navigate to?

Monday, July 27, 2009 6:39 PM by greenway

# re: What’s New In Silverlight 3 – Navigation

Thanks will the video cover Fragments? I'm having trouble when I want to do a popup child window, modify the url, but not reload the view, same when closing the child window.

From reading up on Fragments it seems like I should be able to use it for this, but I can't get it right.

Tuesday, July 28, 2009 1:02 PM by Bill Reiss

# New and Notable 346

NHibernate/Linq/Entity Framework Ayende has released NHibernate Linq 1.0. LINQ and Entity Framework Posts for 7/20/2009+ Data Access Guidance project ASP.NET and Web Programming ARCast.TV - Scott Hanselman on scaling websites with caching ASP.NET Performance

# What’s New In Silverlight 3 – Navigation - Jesse Liberty - Silverlight Geek

Thank you for submitting this cool story - Trackback from DotNetShoutout

Wednesday, July 29, 2009 1:17 PM by DotNetShoutout

# ??????????????? 3??? ????????? ??????(??????) &laquo; jin_u as blog

Pingback from  ??????????????? 3??? ????????? ??????(??????) &laquo; jin_u as blog

# Programming with Silverlight, WPF &amp; .NET &raquo; Was ist neu in SL 3?

Pingback from  Programming with Silverlight, WPF &amp; .NET &raquo; Was ist neu in SL 3?

# re: What’s New In Silverlight 3 – Navigation

At first I was excited to see the Silverlight was supplying an answer to Multi page applications.  But I honestly think this is a rather poor solution for multi page apps.  The great thing about silverlight is that it brings the desktop experience to web based apps.  This approach is nothing more than mimicing the $get tactics of http requests, which forces us to serialize data to a uri before sending a request... lame.  MS, How about giving us a REAL multi page solution rather developing a mimic of a platform that SL is designed to get away from?

Thursday, October 15, 2009 11:25 AM by decius

# re: What’s New In Silverlight 3 – Navigation

you can't put more than one var in url

Uri="/ProductDetail/{productid}/{version}"

MappedUri="/Views/ProductDetail.xaml?ProductId={productid}&version={version}"/>

:'(

Friday, November 06, 2009 4:23 AM by nk54