WPF:将 DataGrid 绑定到列表将 DataGridComboBoxColumn 绑定到列表?
我有一个 DataGrid,其中 ItemsSource 设置为产品列表,并且 我在 DataGrid 中有一个 DataGridComboBoxColumn,其中 ItemsSource 设置为类别列表。这样我希望用户为每个产品选择特定的类别。
我总是收到绑定错误:
BindingExpression path error: 'Categories' property not find on 'object' ''Product' (Hash)
好吧,我不想将 Product 实体的 Category 列表作为 1:N 关系的一部分,尽管就这样。
我想让他们分开。
有人知道解决方法吗?
I have a DataGrid with ItemsSource set to a list of products and
I have a DataGridComboBoxColumn inside the DataGrid with ItemsSource set to a list of categories. That way I want the user to choose a certain category for each product.
I always get the binding error:
BindingExpression path error: 'Categories' property not found on 'object' ''Product' (Hash)
Well I do not want to make the Category list part of the Product entity as 1:N relation, although it would work that way.
I want to keep them separate.
Anyone knows a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建具有静态属性的类
,并使用以下绑定
Create class with static property like
and use following binding
这是一种迟到的回复,但为了分享知识,我发现了这个:
Binding a WPF DataGridComboBoxColumn with MVVM
这个答案表明,并不总是强制将第二个列表转换为静态类,您始终可以指定 RelativeSource 并搜索特定的 Ancestor,然后绑定到 ViewModel 中的“其他”列表。
this is kind of late reply but in order to share the knowledge I found this:
Binding a WPF DataGridComboBoxColumn with MVVM
This answer shows that is not always mandatory to convert the second list to a static class, you can always specify a RelativeSource and search for an specific Ancestor and then bind to the "other" list you have in your ViewModel.
这可能与您的问题相关。
This is probably relevant to your problem.