I want to have an empty item in the comboBox to allow the user to "Unselect" and keep the comboBox empty (Null value).
How can I do that?
I want to have an empty item in the comboBox to allow the user to "Unselect" and keep the comboBox empty (Null value).
How can I do that?
Make your life easier by using a sentinel value. That is, an instance of your view model class that represents nothing.
HTH, Kent
If you take a look at my blog entry here, you can see a binding solution that doesn't require you to "modify" your VM or to add dummy items into a collection that doesn't really fit with your data.
Basically, you use a CompositeCollection in your XAML, which gives you the ability (for instance) to have numeric values in your combo-box, and the text "Please select..." to designate the place holder, which you can't do if you are binding entirely to numeric fields in your model and relying on that to add this magic value.
Read my blog for a fully working example of a clean nullable combobox, see http://www.blueedge.nl/weblog/post/Nullable-ComboBox-in-Silverlight.aspx
The solutions supports 2-way databinding with nullable items.