WPF 中用于绑定的嵌套列表的建议方法
问题:执行嵌套列表的最有效方法是什么,该列表允许在视图中进行数据绑定并了解选择了哪些装运,以便视图中的命令绑定可以在视图模型中的任何嵌套中的适当项目上运行清单?
信息:
我有一个程序,我花了很多时间来了解 WPF 和 MVVM。但现在我有点卡住了。这是一个库存计划。当货物进来时,人们会使用它来输入数据。一批货件包含一系列托盘,而托盘则包含一系列产品。
所以我想知道解决这个问题最明智的方法是什么?我考虑过让 allshipments 类有一个发货集合,shipment 类有一个托盘列表,而pallet 类有一个产品集合。但由于某种原因,我似乎无法通过该绑定来工作。我考虑的另一种方法是让我的所有货件类别都有货件、托盘和产品的列表,我的视图仅将相关托盘拉到感兴趣的货件,并将相关产品拉到感兴趣的托盘,但这并没有'看起来不像 MVVM,而且执行所有属性更改通知的后勤工作已经让我头晕目眩。
Question: What would be the most effective way of doing a nested list which allows for data binding in the view and awareness of what shipment is selected so that command bindings from the view can function in the viewmodel on the appropriate item in any of the nested lists?
Info:
I've got a program that I've been working a lot on to get an understanding of WPF and MVVM. But now I'm kind of stuck. It is an inventory program. People will use it when shipment come in to enter the data. A shipment has a collection of pallets, and pallets have collections of products.
So I was wondering what would be the most advisable way of going about this? I've considered having the allshipments class have a collection of shipments, the shipment class have a list of pallets, and the pallet class have a collection of products. But I can't seem to get the binding to work for through that for some reason. Another approach I've consider is having my all shipments class have a list of shipments, pallets, and products, and my view only pulls up associated pallets to the shipment of interest, and associated products to the pallet of interest, but that doesn't seem like MVVM, and and the logistics of doing all the property changed notification is already making my head spin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一定要选择“allshipments 类有一个发货集合,该发货类有一个托盘列表,而托盘类有一个产品集合”。
关注此博客获取您的绑定工作
Definitely go with "the allshipments class have a collection of shipments, the shipment class have a list of pallets, and the pallet class have a collection of products".
Follow this blog to get your bindings working
Rob Fonseca-Ensor 是对的,使用第一个变体。也许您应该使用 ObservableCollection 而不是 List 来使绑定起作用?
Rob Fonseca-Ensor is right, use the first variant. Maybe you should use ObservableCollection instead of List to make bindings work?