Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 DataForm ComboBox
3 replies. Latest Post by DeborahK on November 27, 2009.
(0)
DeborahK
Member
57 points
37 Posts
11-24-2009 5:52 PM |
I have a combobox bound to a DomainDataSource. If the ComboBox is displayed by itself, it works fine and is populated with the correct values.
If I copy the ComboBox and paste it in a DataField, it no longer populates. I tried adding the SelectedItem property, but it did not seem to help.
Here is my DomainDataSource:
<ria:DomainDataSource x:Name="GenderDataSource" AutoLoad="True" QueryName="GetGendersQuery"> <ria:DomainDataSource.DomainContext> <services:IACodesContext/> </ria:DomainDataSource.DomainContext> </ria:DomainDataSource> <!--<ComboBox x:Name="GenderComboBox" ItemsSource="{Binding Data, ElementName=GenderDataSource}" DisplayMemberPath="CodeText"/>-->
The combobox code commented out above works fine (when it is not commented out, of course<G>).
Here is my DataForm:
<dataFormToolkit:DataForm x:Name="PersonInfoDataForm" Grid.Row="3" Grid.ColumnSpan="3" AutoGenerateFields="False" Header="Person Profile" CurrentItem="{Binding SelectedItem, ElementName=PersonGrid}"> <dataFormToolkit:DataForm.EditTemplate> <DataTemplate> <StackPanel dataFormToolkit:DataField.IsFieldGroup="True"> <dataFormToolkit:DataField LabelStyle="{StaticResource LabelStyle}"> <TextBox Text="{Binding LastName, Mode=TwoWay}"/> </dataFormToolkit:DataField> <dataFormToolkit:DataField LabelStyle="{StaticResource LabelStyle}"> <TextBox Text="{Binding FirstName, Mode=TwoWay}"/> </dataFormToolkit:DataField> <dataFormToolkit:DataField LabelStyle="{StaticResource LabelStyle}"> <TextBox Text="{Binding MiddleName, Mode=TwoWay}"/> </dataFormToolkit:DataField> <dataFormToolkit:DataField LabelStyle="{StaticResource LabelStyle}"> <controls:DatePicker SelectedDate="{Binding DateOfBirth, Mode=TwoWay, Converter={StaticResource DateOnlyConverter}}"/> </dataFormToolkit:DataField> <dataFormToolkit:DataField LabelStyle="{StaticResource LabelStyle}"> <ComboBox x:Name="GenderComboBox" ItemsSource="{Binding Data, ElementName=GenderDataSource}" DisplayMemberPath="CodeText" SelectedItem="{Binding Gender, Mode=TwoWay}"> </ComboBox> </dataFormToolkit:DataField> </StackPanel> </DataTemplate> </dataFormToolkit:DataForm.EditTemplate> </dataFormToolkit:DataForm>
In this code, the Combobox is not populated. Any idea what else I need to do in this case?
THANKS!
11-24-2009 7:03 PM |
After a significant amount of research, it appears that the problem is this:
http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx
When the ComboBox is part of the DataForm, it can no longer see the DomainDataSource defined on the UserControl. THIS SEEMS LIKE A BUG!!
But there was no way I wanted to create all of the code shown in the above link.
Instead ... to fix this I had to make the domain data source into a resource and change x:Name to x:Key. I was then able to access the data source from the ComboBox. So it is now populating.
I still cannot set the default value... so still working on that part...
Min-Hong...
Contributor
3494 points
397 Posts
11-27-2009 3:50 AM |
Hi,
You may check this link, it is an example.
http://weblogs.asp.net/manishdalal/archive/2009/07/03/silverlight-3-combobox-control.aspx
I followed it ,and it worked.
Maybe you forget to override the equals in the shared code?
Best Regards
11-27-2009 10:46 AM |
I wrote a blog post on this here:
http://msmvps.com/blogs/deborahk/archive/2009/11/25/silverlight-and-ria-adding-a-combobox-to-a-dataform.aspx
Hope this helps anyone else with this problem.