将 DataGrid 绑定到矩阵
我有一个如下所示的“矩阵”对象:
public class Matrix
{
public Dictionary<string, string> PropertyBags { ... }
// Sample Property Bag: [{"Column A", "A"}, {"Column B", "B"}]
public List<PropertyBags Row { ... }
}
我想知道在 WPF DataGrid 中显示对象的实用解决方案是什么?
谢谢。
I have a 'matrix' object like follows:
public class Matrix
{
public Dictionary<string, string> PropertyBags { ... }
// Sample Property Bag: [{"Column A", "A"}, {"Column B", "B"}]
public List<PropertyBags Row { ... }
}
I wonder what's a practical solution for displaying my objects in WPF DataGrid?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以在网格视图后面的代码中完成此操作。这个想法是将自定义数据集绑定到 grid.DataSource 属性,然后动态添加列,请参阅下面的链接示例。
另外,第二个链接提供了一个使用 Dependency Property 的好示例,该属性绑定到 XAML 中网格的
ItemsSource
,DP 还提供了OnPropertyChangedCallback
,因此每次更新数据集时新值:示例链接:
Yep, you can do it in code behind of a Grid View. The idea is to bind a custom data set to a
grid.DataSource
property and then add columns dynamically, see examples by links below.Also the second link provides an good example using Dependency Property which bound to a
ItemsSource
of a grid in XAML, also DP hasOnPropertyChangedCallback
provided so each time you update a data set by new value:Links to the examples: