So that you don’t need to submit your application to get it’s id and resubmit it.
For my future WP7 application Warnygo, I needed to get its id for several reasons. For example, use it with the ShareLinkTask or send it to my services.
As you may know, you can find your application id in the WMAppManifest.xml. It’s the ProductID attribute in the App node.
When you first create your application with Visual Studio, you get a random one. But you will get a new one through the marketplace submission process. So how to get your application id in your application once submitted?
Well, the ugly way is to:
Submit your application to the marketplace so that you can get the real application id.
Then update your application with the new application id wherever you need it.
To finish resubmit your application.
Personally I don’t like this way!
The clean way that I propose is to directly read the application id in the WMAppManifest.xml file. Check this code:
A looooong title for a recurring question when you start developping a Windows Phone 7 Application.
It’s been a while since my last article (April 21, 2011! Wo!), but time is running so fast and I was very busy with several projects.
One of these was real live tracking in rally with WP7 and Bing Maps for the International Rally of Burgundy. See WP7 for tracking in Rallye on WPCentral for more details.
So go back to the subject of this article. I recently restarted the development of a WP7 application named Warnygo from scratch with Mango tools and I faced the same questions.
Reminder about NavigationService
As you know when you want to navigate from one view to another, you use the NavigationService like that:
As you may notice, we are setting the view navigation parameters in the Navigated event. This event is triggered before the OnNavigatedTo in the target view.
Example of use
For the purposes of this article I have created a simple Windows Phone 7 solution (You can download it bellow) to show you how to use the two NavigationService extensions. In this solutions we have three views:
As you see the view is decorated with our custom attribute named ViewInfos where we specify the view path.
When we click on the Navigate to products button we are calling the first NavigationService extension, because we simply need to navigate to the product list view, without parameters.
On the other hand, in the product list view we need to pass the selected product to the product details view.
We are navigating to the product details view when the application bar button is clicked or when a product is selected. We specify that the navigation parameters type is EditProductParameters.
We can then use the navigation parameters in the product details view:
To make this article simple I didn’t use MVVM pattern. In fact in my own WP7 framework I didn’t created those two NavigationService methods as extensions. Initially it is two methods in my ViewModelBase so I can navigate from a ViewModel to a View. All this to say that you can use those extensions even if you are developing your application using MVVM pattern.
I’d like to add that the solution I give you here is not THE solution it is a way to answer this article main questions about the NavigationService.
Summary
We have seen how to Navigate from one view to another passing a complex object parameter without specifying the target view Uri in a Windows Phone 7 Application.
Isn’t that cool?! I mean, supposing that you are developer of course, because if you’re not you don’t give a sh** about that! đŸ™‚
No, to be serious our code is way cleaner like that, isn’t it?