views:

131

answers:

2

I have a silverlight combobox inside of a dataform as follows:

    <dataControls:DataForm x:Name="newScheduleMasterForm" Height="350" Width="450"  MinWidth="400"
                           VerticalAlignment="Top"    
                           CommandButtonsVisibility="None"
                           Header="Add New Master Schedule"
                           HorizontalAlignment="Left" AutoGenerateFields="False" ContentLoaded="newScheduleMasterForm_ContentLoaded"  >
        <dataControls:DataForm.EditTemplate>
            <DataTemplate>
                <StackPanel>
                    <dataControls:DataField>
                        <ComboBox x:Name="cbScheduleType" SelectedItem="{Binding Schedule, Mode=TwoWay}" SelectedIndex = "0"
                              ItemsSource="{Binding GetScheduleTypeValues, Source={StaticResource validDataSource}}"
                        />
                    </dataControls:DataField>
                </StackPanel>
            </DataTemplate>
        </dataControls:DataForm.EditTemplate>
    </dataControls:DataForm>

The combobox cbScheduleType ItemsSource has values of "Interior" and Exterior. I am unable to display the default selected value "Interior" in the text box of the combobox. Is there a way to do it.

Thanks in advance Mohit

+1  A: 

The problem is that you're trying to both set SelectedIndex and bind Selected Item. I would just set Schedule to Interior in your constructor in codebehind and remove the SelectedIndex attribute.

David Hay
I tried that. Does'nt seem to work. The combox's text box does not display the "Interior" text value.
Mohit
A: 

There are some problems with data binding the SelectedItem property in the default Silverlight ComboBox control.

One way to work around this by creating a custom control that inherits from ComboBox and adds a SelectedValue dependency property.

There's a good example of this on Rockford Lhotka's blog at: http://www.lhotka.net/weblog/SilverlightComboBoxControlAndDataBinding.aspx

Neil Duxbury