Friday, June 11, 2010

ComboBox Solutions for Silverlight 3 and Silverlight 4

Silverlight 3 ComboBox Solutions

Proper Way to bind ComboBoxes to Associated Entities / Foreign Keys? Look about half way down for a post by ScottNZ on 8/13/2010 for the good idea.

Silverlight 3 ComboBox Control This solution works well I think and is even compatible with Silverlight 4. The one enhancement I would make to it for SL4 is use the SelectedValue and SelectedValuePath instead of SelectedObject. If you use SelectedValue and SelectedValuePath then the DataForm (DataField really) knows how to make it appear with a red box around it if you mark the foreign key property (if you are using RIA) as Required and there is nothing selected. Very nice. The error message is lame, but still better than nothing.

Silverlight ComboBox control and data binding by Rockford Lhotka Basically gives source code on how to make the SL3 ComboBox work much like the SL4 ComboBox. I have not tried it, but he is good so I’m sure it works, and it is a good example of how to extend a Silverlight control.

Just Geeks: A better way of using the ComboBox on a DataForm in Silverlight 3 – I wrote this one. Not too much different that most solutions above or at least some combination of them. I do go into what to do for POCO entities.

Just Geeks: Using a ComboBox on a DataForm for Silverlight 3 – I wrote this one also. It was my first attempt at using a ComboBoxes. The biggest take away from it is that you can populate the ComboBox in the ContentLoaded event of the DataForm.

Silverlight 4 ComboBox Solutions

NOTE: These won’t work in Silverlight 3 because SL4 added the SelectedValue and SelectedValuePath properties that work with the EF ForeignKey support.

Binding to Silverlight ComboBox and Using SelectedValue, SelectedValuePath, and DisplayMemberPath This one is actually good but assumes you know how to populate your ComboBoxes. I recommend using resources.

Silverlight 4 Rought Notes: SelectedValue It does a pretty good job of showing how to use the new SelectedValue, SelectedValuePath, etc. It uses locally defined data in example so it you’ll have to make the leap on how this is done in real code.