WPF 列表视图之间的多对多绑定
我有两个列表视图,一个用于图像,一个用于标签,它们具有多对多关系。
两个列表视图都绑定到 EF 对象的 ObservableCollection。标签列表视图还有一个复选框列。
当我从列表视图中选择图像时,我希望在另一个列表视图上检查关联的标签。我需要 TwoWay 绑定来根据是否检查来创建和删除关系。
我该怎么做?
I have two listviews, one for Images and one for Tags, which have a many-many relationship.
Both listviews are bound to ObservableCollection of EF objects. The Tag listview also has a checkbox column.
When I select an Image from the listview I'd like the associated Tags to be checked on the other listview. I need TwoWay binding to create and remove the relationships based on being checked or not.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的VM中,你有两个所有图像和标签的ObservableCollection...我认为你可以使用关联图像或标签的另外两个ObservableCollection,当你选择一个图像时,你可以将关联的标签与这个ObservableCollection绑定,反之亦然。
其他解决方案您可以将关联的项目与所选项目绑定(“SelectedItems={Binding Path=SelectedItem.Tags, ElementName=MyImageListBox}”或类似的内容)。
in your VM you have two ObservableCollection of all Images and Tags... I think you can use two others ObservableCollection of associated Images or Tags, when you select an Image you can bind the associated Tags with this ObservableCollection and vise versa.
Other solution you can bind the associated items with selected item ("SelectedItems={Binding Path=SelectedItem.Tags, ElementName=MyImageListBox}", or something like that).
我的工作如下:
大致如下:
I've got this working as follows:
Something along the lines of: