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.

Windows Phone 7 development

Well my current cellphone is a new HTC smartphone with the Window Phone 7 OS! It’s the HTC Trophy and I have to say the OS and the device are just brilliant.
But to be honest, the fact that you can just code .Net apps for it, made it a winner in my books.

So let me introduce you in the Windows Phone 7 development area.
Here are some of my current findings with it.

The first thing to know is that when you are developing it will be in a WPF/Silverlight environment, so be sure to get the hang of XAML or even better, get your Expression Blend skills up to date.

Secondly, the best way to create good, manageable code, is by using the MVVM pattern. The fact that this pattern is not only restricted to the Windows Phone 7 environment makes it beneficial to learn it for other projects. MVVM is based on viewmodel property binding for your view data.
Now to get a good start with MVVM, you better use a framework that integrates well with the Windows Phone 7. My personal favourite is MVVM Light Toolkit from Laurent Bugnion!
Get the details here: and here:

The only drawback in my mind, is the fact that currently you are by default limited in possible api uses from the Phone itself. In other words, some of the nice controls or features used on the default up front installed phone apps are not available to the developers. So another good thing to know is what frameworks/libraries are out there to overcome this…

My current list of libraries are
* Silverlight for windows phone toolkit:
* Coding4Fun windows phone toolkit:
* WP7 Contrib framework: ( this is actually already a superset of other libraries with custom additions )

When you add these to your Windows Phone 7 tool set, you’ll get plenty of controls and helpers that are needed when you start developing.

To show of some of the features of these frameworks I started a CodePlex project, called WP7Cycling!
The main reason for this project is just for myself to get to know the development environment, but it will also benefit other developers in showing what can be done in combination with the given toolkits!
For now it doesn’t have any downloads, so just grab the source code to get the complete project if you want to see it running in the emulator:

Currently I created a simple MainPage with an integrated Bing Maps control and when you press the Get current location button on the appbar, the map will center itself on the current GPS coordinate location of the phone.

Have fun coding and any tips or tricks are always welcome 🙂