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”/>