Silverlight 3 combobox binding to a CSLADataProvider factory parameter

Silverlight 3 combobox binding to a CSLADataProvider factory parameter

Old forum URL: forums.lhotka.net/forums/t/7951.aspx


DancesWithBamboo posted on Thursday, November 05, 2009

I'm being dense today so I need some help.  I'm trying to bind a combobox in SL3 such that when an item is selected, the value of the item updates a different csladataprovider's factory parameter.  This was standard stuff in WPF but I'm just not "getting it" in the SL world.  I followed this: http://www.lhotka.net/weblog/SilverlightComboBoxControlAndDataBinding.aspx blog entry to get a working combo with a SelectedValue property. 

Now how do I get that property into my factory method parameters on another data provider?

RockfordLhotka replied on Thursday, November 05, 2009

I don't think SL3 supports the "reverse binding" necessary to make this work without some code or intermediate entity.

You might try subclassing CslaDataProvider to add a SelectedValue dependency property that you can bind to from the combobox. Or you might find that switching to a viewmodel approach is simpler than the data provider approach for things like this, though I think adding a property to a CslaDataProvider subclass is a fine solution.

Just handle the case where the property changes (not in the setter - that doesn't always run - but in the static property registration code), and when the property changes have your code in the data provider set the factory parameter collection and call Refresh().

DancesWithBamboo replied on Thursday, November 05, 2009

Thanks Rocky for the subclassing suggestion--hadn't thought of that.  Somehow I just knew "code" was going to be the answer.  Seems like the xaml and binding in SL 3 still isn't quite there yet.  I haven't embraced mvvm (not sure it will fit in my head) yet so I am going with the dataprovider method at least for now.

Copyright (c) Marimer LLC