Skip to main content

Microsoft Silverlight

Answered Question DataForm ComboBoxRSS Feed

(0)

DeborahK
DeborahK

Member

Member

57 points

37 Posts

DataForm ComboBox

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!

DeborahK
DeborahK

Member

Member

57 points

37 Posts

Answered Question

Re: DataForm ComboBox

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 Tang - MSFT
Min-Hong...

Contributor

Contributor

3494 points

397 Posts

Answered Question

Re: DataForm ComboBox

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

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

DeborahK
DeborahK

Member

Member

57 points

37 Posts

Answered Question

Re: DataForm ComboBox

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities