0
votes

I'm working on a Silverlight 4 WCF RIA Services app. I created a Presentation Model for my Stock entity, which is working fine. My trouble (well, one of my troubles) is when I try to databind a combobox to lookup a StockType.

I can set the combobox items source in xaml all OK (i.e. I can see the list of items in the dropdown), but the selected item is not bound to the CurrentStock.Type property. CurrentStock is a property on my viewmodel, and it's working fine for all the other fields, just not the comboboxes.

<Combobox 
    ItemsSource="{Binding Source={StaticResource StockTypeDataSource}, Mode=TwoWay}"
    DisplayMemberPath="Type"
    SelectedValue=="{Binding Path=CurrentStock.Type}"
    SelectedValuePath="Type"/>

I believe this is because the combobox data source is in a different domain context to my StockPresentationModel entity, am I right? If so, can I work around that, or do I need to pull the Stock_Type entity into my Stock presentation model? Or can I somehow load my entities (Stock and Stock_Type) into my viewmodel and correctly set the combobox items source from there?

This is my first project using Silverlight and RIA, and I have hunted and searched and experimented for an embarrassing amount of time, so any help would be much appreciated.

1
You're right in assuming the problem is the entities being in different DomainContexts. I recommend putting them in the same context for this scenario. Optionally, you can get around that requirement by using the primary key in place of the entity in your bindings (Stock.Type.ID). - Kyle McClellan

1 Answers

0
votes

Make sure that you have [Include] attribute in Type property in Metadata of entity class of RIA service.