Setting up an ApplicationBar using XAML

As the sample code from Microsoft uses code to create an application bar, I thought it might be interesting to show how this is done using XAML only as I find it a bit cleaner.

First thing to remember is that in order for a PhoneApplicationPage to make use of a ApplicationBar created in XAML, it needs to first have been declared before the page is instantiated. This means adding the definition to the parent’s resources, in this case App.xaml. If you don’t do this, you’ll end up dancing with null reference exceptions.

So, to reach the ApplicationBar class at all, we need a reference to Microsoft.Phone.Shell.