如何使用绑定动态地将列添加到DataGrid [英] How to dynamically add columns to a DataGrid using binding
本文介绍了如何使用绑定动态地将列添加到DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个
List<List<MyClass>>
这基本上是一个nXm矩阵,每个节点都是MyClass上的一个实例。
我想在数据网格(WPF,MVVM)中显示它。我在WinForms C#(事件驱动编程)中完成了这个,我想用MVVM模式在WPF中重写它。我不清楚如何在MVVM模式中执行此操作。
which is basically a nXm matrix with each node being an instance on MyClass.
I want to display this in a datagrid (WPF , MVVM). I have done this in WinForms C#(Event Driven Programming) and I want to rewrite this in WPF using MVVM pattern. I am not clear as to how to do this in MVVM pattern.
推荐答案
您是否有使用DataGrid的具体原因?
数据的设计方式,我认为< ItemsControl>将有助于获得您正在寻找的网格。你可以使用< UniformGrid>会导致所有''节点''大小相同的元素。
有一个使用< ItemsControl>的示例和< UniformGrid> 此处 [ ^ ]
Do you have a specific reason for using a DataGrid?
The way your data is designed, I would think an <ItemsControl> would serve to get the grid you are looking for. You could use a <UniformGrid> element which would cause all of the ''nodes'' to be the same size.
There is a sample of using <ItemsControl> and <UniformGrid> here[^]
这篇关于如何使用绑定动态地将列添加到DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文