![](/img/trans.png)
[英]Dynamically generating Row and Column headers for DataGrid using templates WPF
[英].NET 4.0 WPF, DataGrid with Row and column headers
我想要一个带有行和列标题的 DataGrid。 以下是我的数据结构:
public class PointInfo
{
public Tuple<int, int> Coordinate { get; set; }
public int DataAtPoint { get; set; }
private PointInfo(){}
public PointInfo(int rowIndex, int columnIndex)
{
Coordinate = Tuple.Create(rowIndex, columnIndex);
}
}
我想创建一个 DataGrid 并将列 header 分配给columnIndex
并将行 header 分配给rowIndex
。 我猜这是可能的。 我看过这个问题。 它非常接近解决问题。
DataGrid 的数据将来自PointInfo
对象列表。 它基本上就像一场战斗
谢谢!
不是您问题的完整答案,但 WPF DataGrid 不擅长处理可变数量的列。
您可以做的是动态创建一个匿名类型(例如, http://jacobcarpenter.wordpress.com/2008/03/13/dictionary-to-anonymous-type/ ),然后打开自动生成列通过反射来做到这一点,否则你将不得不在代码中定义你的列。
另请注意,绑定列 header(而不是直接设置它)可能会变得很麻烦,因为 DataGrid 列不继承父级的 DataContext,但这里提供了一种解决方法: http://blogs.infragistics.com/blogs/josh_smith/存档/2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.