WPF TwoWay 将一些元素绑定到 ObservableCollection
我需要将一些 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>
我想将我的集合绑定到所有组合框并保存每个组合框的选定项目。 如果我填充一个集合并将其绑定到双向模式下的所有组合框,我会得到:
我认为我需要包含一些类似集合的辅助类。怎么做呢?
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:
I think I need helper class that will contain some similar collections. How to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我假设 CoefLinksTableType 属性位于 CollectionCoefContainers 内的项目上?
在这种情况下,这应该有效,除非您在
CollectionCoefContainers
中重复使用相同的实例。例如,
像这样的东西会像你所描述的那样表现。
解决方案是
让您定义CollectionCoefContainers和CollectionCoefLinksTable可能会很有用
So I assume the
CoefLinksTableType
property is on the items insideCollectionCoefContainers
?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.
The solution would be
It might be useful to have you definitions of
CollectionCoefContainers
andCollectionCoefLinksTable