WPF TwoWay Binding some elements to ObservableCollection
I need bind some ComboBoxes to one ObservableCollection.
I have this ListView.
<ListView x:Name="lwCoefTables" Grid.Column="1" ItemsSource="{Binding Source={StaticResour开发者_如何学Cce 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?
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
加载中,请稍侯......
精彩评论