如何将 WPF Datagrid itemssource 绑定到 Collection of Collections?

发布于 2024-08-17 09:47:29 字数 566 浏览 5 评论 0原文

将 WPF DataGrid ItemsSource 绑定到 ObservableCollections 的 ObservableCollection 的最佳方法是什么?

例如,

public ObservableCollection<ObservableCollection<MyDataItem>> DataValues = new ObservableCollection<ObservableCollection<MyDataItem>>();

MyDataItem 可能如下所示:

public class MyDataItem
{
    public string Caption { get; set; }
    public string DataValue { get; set; }
}

我可以假设集合的集合不是锯齿状的,并且它们都包含相同数量的“列”

是否可以将每列动态绑定到 MyDataItem 对象的“DataValue”属性或我是否需要将数据打包成更容易绑定的结构?

What is the best approach to bind a WPF DataGrid ItemsSource to an ObservableCollection of ObservableCollections ?

e.g.

public ObservableCollection<ObservableCollection<MyDataItem>> DataValues = new ObservableCollection<ObservableCollection<MyDataItem>>();

where MyDataItem may look like this:

public class MyDataItem
{
    public string Caption { get; set; }
    public string DataValue { get; set; }
}

I can assume the collection of collections isn't jagged, and they all contain the same number of "columns"

Is it possible to bind each column dynamically to the 'DataValue' property of the MyDataItem objects or do I need to pack the data into an easier structure to bind to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2024-08-24 09:47:29

这可以通过使用集合派生类作为内部对象并在其上实现 ICustomTypeDescriptor 来实现 - 请参阅有关该主题的类似 SO 问题(用 Silverlight 标记,但想法相同)

Silverlight DataGrid - 绑定到对象集合的集合。< /a>

This is possible by using a collection-derived class as the inner object, and implementing ICustomTypeDescriptor on it - See a similar SO question on the topic (tagged with Silverlight, but same idea)

Silverlight DataGrid - Binding to a Collection of Collections of objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文