![](/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.