WP7: Navigating to a page in different assembly
published on: 2/14/2011 | Views: N/A | Tags: Navigation
by WindowsPhoneGeek
In this quick tip I am going to demonstrate how to navigate to a page in different assembly in Windows Phone 7.
Generally when you want to navigate to a page in the same assembly there are three basic ways to navigate between pages in your app.
- Using the HyperlinkButton and set the NavigateUri property to the name of the page that you want to navigate to.
- NavigationService.Navigate() - navigate to any particular page using its uri.
- NavigationService.GoBack() - this will take the user back one page in their navigation history. (Do not forget to check if there is a page in the navigation history.)
WP7 Uri String Format
- Internal Page
/{PathToResource}
External Page
/{assemblyName};component/{PathToResource}
For more information about how to access a page by its Uri and all supported Uri formats take a look at the MSDN Documentation: Resource Files
Navigate to a page in external assembly
NOTE: If you want to navigate to an external assembly you must add a reference to it in the current project.
Now lets create two separate Windows Phone 7 Application projects called:
NavigationTestProject WP7SampleProject12



We will navigate to the NavigationTestProject MainPage from our WP7SampleProject12.
Example1: Navigate to external assembly using NavigationService.Navigate()
Here is the source code that shows how to navigate to external assembly and how to navigate to a page from the current assembly using the NavigationService.Navigate() method:
private void Button_Click(object sender, RoutedEventArgs e)
{
//Navigate to a page in an external referenced assembly
NavigationService.Navigate(new Uri("/NavigationTestProject;component/MainPage.xaml", UriKind.Relative));
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
//Navigate to a page in the current assembly
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}
Example2: Navigate to external assembly using HyperlinkButton
Here is the source code that shows how to navigate to external assembly and how to navigate to a page from the current assembly using HyperlinkButton :
<HyperlinkButton NavigateUri="/NavigationTestProject;component/MainPage.xaml" Content="Navigate to external assembly"/> <HyperlinkButton NavigateUri="/Page1.xaml" Content="Navigate to a page in this assembly"/>
NOTE: In this way you can also load different resources from external assemblies like controls, images, styles etc.
Here id the full source code.
I hope that this post was helpful.
You can also follow us on Twitter @winphonegeek
Comments
Formatting the Uri
posted by: Kesh on 6/26/2011 4:43:15 AM
Whenever I use the following code navigation fails
NavigationService.Navigate(new Uri(string.Format("/ExternalPages;component/ItemViewPage.xaml?parameter={0}", selectedItemData.Name), UriKind.Relative));
What could be the cause?
error with reference
posted by: kapil on 8/18/2011 12:52:21 PM
followed above steps: this is what Iam getting. Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)
This is the error Iam getting :( what could be the reason
Invoking an app from with an app
posted by: McKnight on 9/3/2011 12:58:42 PM
Does this work when trying to invoke an app from within an app? I am currently developing an app and I want to send messages using twitter, how do I go about referencing the twitter client from my app? Any ideas?
Navigating to a page in different App ??
posted by: Venetasoft on 1/21/2012 9:57:52 PM
Would be great if you discover a way to navigate to a page in different app. If both apps are from the same publisher (me) we know exctly the page name....
Any ideas ;) ?
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
