我需要将一些ComboBox绑定到一个ObservableCollection。
我有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>
我希望将我的集合绑定到所有ComboBox并为每个ComboBox保存选定的项目。 如果我填写一个集合并将其绑定到TwoWay模式中的所有组合框,我得到这个:
我认为我需要包含一些类似集合的辅助类。怎么做?
答案 0 :(得分:3)
所以我假设CoefLinksTableType
内的CollectionCoefContainers
属性是<{1}}?
在这种情况下,这应该可行,除非您在CollectionCoefContainers
内重复了相同的实例。
e.g。
这样的事情就像你描述的那样。
var vm = new VM();
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
CollectionCoefContainers.Add(vm);
解决方案是
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
CollectionCoefContainers.Add(new VM());
让您定义CollectionCoefContainers
和CollectionCoefLinksTable