While working on an MVVM project, I was recently debugging an issue with some of my Silverlight ComboBoxes.  The ComboBoxes were bound to pre-set values in the ViewModel, and yet were showing up empty when rendered on the page.  What was really troubling was that some ComboBoxes were working correctly, but others were showing up blank, when they were bound to the same ViewModel and everything looked to be exactly the same!

Here’s a sample project where I’ve reproduced the problem:

Both ComboBoxes are bound to the same ItemsSource, and both have simple int values as their bound SelectedValue ...

Someone recently asked me for advice on how to bind the visual state of a Silverlight control to a property of the view-model.  Specifically, they had a Boolean property on their view-model named something like IsExpanded that they wanted to control the expanding and collapsing of a control in the view with the value of this view-model property.

It was such a fun sounding challenge—and one that seemed like it would be very useful to have for many situations—that I couldn’t resist creating a simple solution. 

Here’s What I Created (Silverlight 4 Plug-In Required)

Get Microsoft Silverlight

 

Here’s How I Did It...

I love the M-V-VM pattern for Silverlight and WPF applications.  It’s beautiful and works very well, but sometimes it is too verbose, particularly in the ViewModels’ INotifyPropertyChanged implementations.  I find that I spend too much time on the repetitive plumbing tasks that could otherwise be spent programming the actual application logic.

There are many tools and frameworks out there to speed up and simplify MVVM (Caliburn, MVVM Light, WAF, etc.), but I just discovered a very simple tool that goes a long way toward making MVVM more useable. 

It’s called NotifyPropertyWeaver and it solves the problem ...