Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please help to fix the below issue. I have Combobox inside listbox item datatemplate so that I can load multiple combobox but same itemsource

XML
<StackPanel>
  <ListBox Width="400" Name="lstFiles" ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
      <DataTemplate>
        <Grid Name="dataGrid">
          <Grid.RowDefinitions>
            <RowDefinition/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <TextBox Name="dragFileName"
                   Margin="5,0,0,0"
                   Text="{Binding fileName, UpdateSourceTrigger=Default}" />
          <ComboBox Grid.Row="0"
                    Grid.Column="1"
                    Margin="5,0,0,0"
                    Name="cboDragDocType"
                    ItemsSource="{Binding dragDocType, UpdateSourceTrigger=LostFocus, Mode=TwoWay}"  
                    Text="{Binding dragDocTypeText}"
                    IsEditable="True"
                    IsReadOnly="True" />
          <Button Name="dragDelBtn"
                  Grid.Column="2"
                  Height="20">X</Button>
        </Grid>
      </DataTemplate>
    </ListBox.ItemTemplate>
  </ListBox>
</StackPanel>


Data is loading in comboBox by using ObservableCollection property. In Initialize method i do for loop method to get multiple items. Problem scenario: Select item from the dropdown1 --> then Select item from the dropdown2 -->Again click dropdown1, Now dropdown1 itemssource is empty.
Posted

1 solution

There is some strange behavior of a binding getting lost.
I experienced something similar with a combination of a combobox and a textbox, with Textbox.Text bound to the ID property of a DependencyProperty which is in turn bound to the SelectedItem of the combobox; the user could type the id and a reverse selection function would update that property which is bound to ComboBox.SelectedItem (not to ComboBox.SelectedItem directly, that would be expected to break the binding).
Eventually, I stored the BindingExpression, and re-applied it in ComboBox_DropDownOpened.
Not a beautiful solution, more of a WTF, but it works.
Perhaps such a work-around could be helpful in your case, too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900