Performance progress bar not displaying after updating to Mango

I’ve been busy over the last few weeks trying to finish my Windows Phone 7 app and recently decided to take the plunge and update it to run on the upcoming Mango release.

Surprisingly I haven’t had too many problems. The only thing that caught me out was remembering to also recompile all the various utility dlls that I had included in my solution and forgot that I was still using! For example, I had included in my solution the Silverlight ZXing, so I had to download the source for that and upgrade it to 7.1.

One thing that did catch me out was that after upgrading everything to 7.1, my performance progress bar (installed from the Augustrelease of the Silverlight Toolkit for Windows Phone) had stopped displaying when the app was busy doing something.

I use the performance progress bar bound to a property in my view model and toggle the display through raising property change events on the property. Everything else was updating correctly just the performance progress bar wasn’t. It turns out that this is a bug in the August release of the toolkit with the performance progress bar and will be fixed in a future release.

To temporarily get around this and fix this I added the following code in the page loaded event in my code behind for my view to reset the binding on the performance progress bar once the view had loaded.

// Following code is required to fix bug in Windows Phone Toolkit - August 2011 
if (progressBar != null)
     progressBar.SetBinding(PerformanceProgressBar.IsIndeterminateProperty, new Binding("Busy"));

This basically rebinds the IsIndeterminate property of the progress bar to the property in my view model called “Busy”. After doing that the performance progress bar shows/hides correctly.

Binding an MVVM Command to a listbox item

If you are trying to bind a Command to a listbox item that is on a View bound to a ViewModel, you may have been banging your heard trying to work out why the Command wasn’t firing ( I was anyway! ). The problem is that Silverlight is trying to find the Command in the context of the control within which it is bound. So in my instance, it was trying to find the Command within the ItemSource of the listbox, rather than looking in the ViewModel which is where definition for my Command exists.

Fortunately, I’m using the MVVM Light Toolkitframework  for my MVVM implentation in my Windows Phone 7 app. This has a really simple feature where you can find the ViewModel through a ViewModelLocator, so the binding on my EventToCommand becomes:

Command="{Binding Source={StaticResource Locator}, Path=Main.DeleteCommand, Mode=OneWay}"/>

where Main is the name of my ViewModel. Simple!