3

I need bind some ComboBoxes to one ObservableCollection. I have this ListView.

<ListView x:Name="lwCoefTables" Grid.Column="1" ItemsSource="{Binding Source={StaticResource CollectionCoefContainers}}">
<ListView.ItemTemplate>
    <DataTemplate>
        <ComboBox x:Name="cmbCoefTableTypes" ItemsSource="{Binding Source={StaticResource CollectionCoefLinksTable}}"  
                SelectedItem="{Binding CoefLinksTableType, Mode=TwoWay}" Grid.Column="1" VerticalAlignment="Center" 
                HorizontalAlignment="Left" Width="180" DisplayMemberPath="Name">
        </ComboBox>
    </DataTemplate>
</ListView.ItemTemplate>

I want bind my collection to all ComboBoxes and save selected items for each ComboBox. If I fill one collection and bind it to all comboboxes in TwoWay mode I get this:

Picture

I think I need helper class that will contain some similar collections. How to do that?

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
algreat
  • 7,762
  • 5
  • 38
  • 52

1 Answers1

3

So I assume the CoefLinksTableType property is on the items inside CollectionCoefContainers?

In which case this should work, unless you have the same instance repeated inside CollectionCoefContainers.

e.g.

Something like this would behave as you describe.

var vm = new VM();
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);

The solution would be

CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());

It might be useful to have you definitions of CollectionCoefContainers and CollectionCoefLinksTable

Ray
  • 43,353
  • 23
  • 121
  • 168