Windows Phone 7 development

Currently I released 2 Windows Phone 7 apps to the Microsoft Marktplace. The creation of both apps was not that difficult, because when you want to develop for wp7, there are several good reusable libraries out there!

Let me zoom in on one in particular, called WP7Contrib! It’s a wp7 library that is available on CodePlex, so the sourcecode is also available! But why am I using it, well let me give you some examples.

* Tombstoning
Each time your wp7 app gets tombstoned, there is a great chance you’ll want to ‘save state’, this helps the user experience of your app. There are several good examples out there that handle this, but I like the implementation of it in wp7contrib.
Basically you’ll create a new ViewModelBase class that implements 2 methods: IsBeingActivated(IStorage storage); and IsBeingDeactivated(IStorage storage); Now when you create a ViewModel, you’ll inherit from this base class, and because wp7contrib has a StorageService that gets passed along as parameter, you can use it to Write and Read data to/from it!
So each time an app gets tombstonded the IsBeingDeactivated method is called on each instantiated ViewModel, enabling you to write code like this: storage.Write(“zoomLevel”, this.ZoomLevel); This example will write the current value of a local property to the StorageService and when the app resumes you can put following code in the IsBeingActivated method: this.ZoomLevel = storage.Read(“zoomLevel”);
And presto, your View will again contain the data the user had put in before tombstoning!

* Isolated Storage
A similar feature is a nice wrapper around the Isolated Storage called StoreSettings. It gives you some method calls that are easy to use! Some examples:
– this.SettingsService.Write(“UserName”, this.UserName); This will store a given View textbox to the Isolated Storage
– this.SettingsService.TryToRead(“UserName”, out userName); This will try to retrieve the value back again, it will return True if the Key was found in the Isolated Storage

* Page navigation
Page navigation from ViewModels in a MVVM app is something that needs to be addressed correctly! Because when you want to submit an app to the marktplace, this is something that has to be working 100% and there are even some rules applied to it.
My tip, just use the NavigationService available in wp7contrib! If you want to ‘navigate’ to another view from your viewmodel, you’ll only have to add following code: this.SettingsCommand = new RelayCommand(() => this.NavigationService.Navigate(ViewModelLocator.SettingsPageUri));
Side note here, I’m setting up a RelayCommand in the constructor of the ViewModel, so that I can trigger this from an appbarbutton in the View!

* Bing Maps location
One last item that I’m a huge fan of in this wp7contrib lib, is the LocationService! One of my apps has Bing Maps integrated and when you need to get a current location fix ( or you want to track location for a period of time ), again you’ll have to write a lot of code to get it done ‘right’.
But with wp7contrib you’ll only need to call the correct methods and everything will be handled for you!
In my app I current allow the user to get his current location fix from the push of an appbar button, with this I’m triggering following code:
_currentSubscriber = _locationService.Location()
.Subscribe(location => this.CurrentPosition = location);

What it does, is fire up the location service and return the current phone location if it is available! When I get it, I’ll just set the CurrentPosition, what in my app is a MVVM binded property to a pushin on the BingMaps control in my view… and presto the current location is visible!

There are also some cool controls available and the one I like most is the SmartTextBlock, just take a look here for the implementation.

Well the list could go on, but currently these 4 are my mostly used ones! I just have to say that wp7contrib helped me speed up my wp7 app development and I would suggest you’ll check it out.
It is available on the wp7contrib codeplex site and the main page contains a good overview of most of the features.