Navigating to Pages in different assembly in Windows Phone 7

The navigation system allows you to easily navigate to other XAML pages in your project:

NavigationService.Navigate(new Uri(“MyOtherPage.xaml”, UriKind.Relative));

But what if you want to navigate to a page that isn’t in the same project?

Fortunately this is easy enough once you understand the syntax of a URI path.

URI’s in Silverlight are a very limited subset of the pack syntax in WPF.  The generalised format of a URI in silverlight is:

/{assemblyName};component/{pathToResource}

Where {assemblyName} is the name of the assembly containing the XAML page (just the name without the .dll extension) and {pathToResource} is the path to the XAML file.  Note: The assembly name you provide must an be assembly referenced by your project.

So if the external assembly called External.dll contains a page called MyOtherPage in a folder called Pages the URI would be /external;component/Pages/MyOtherPage.xaml.  Thus the code would be:

NavigationService.Navigate(new Uri(“/external;component/Pages/MyOtherPage.xaml”, UriKind.Relative));

This type of URI format doesn’t just work for navigation.  It can be used for any type of resource that exists in an external assembly.  To load an image from another assembly you could use:

<image source=”/otherAssembly;component/Images/myImage.jpg”/>

About these ads

2 thoughts on “Navigating to Pages in different assembly in Windows Phone 7

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