.NET 4.0 WPF,带有行和列标题的 DataGrid

发布于 2024-11-04 19:40:49 字数 622 浏览 0 评论 0原文

我想要一个带有行标题和列标题的 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 并将列标题分配给 columnIndex 并将行标题分配给 rowIndex。我猜这是可能的。我看过这个问题。它已经非常接近解决问题了。

DataGrid 的数据将来自 PointInfo 对象的列表。它基本上就像一场战斗

感谢!

I'd like to have a DataGrid with row and column headers. Following is my data structure:

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);
    }
}

Id like to create a DataGrid and assign column header to the columnIndex and assign row header to rowIndex. Im guessing this is possible. Ive had a look at this question. It comes quite close to solving the issue.

Data for the DataGrid will come from a list of PointInfo objects. Its basically like a Battle

Thanks!

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

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

发布评论

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

评论(1

离旧人 2024-11-11 19:40:49

不是您问题的完整答案,但 WPF DataGrid 不太擅长处理可变数量的列。

您可以做的是动态创建匿名类型(例如 http://jacobcarpenter.wordpress.com/2008/03/13/dictionary-to-anonymous-type/),并打开自动生成列,以便通过反射来实现,否则您将得到在代码中定义您的列。

另请注意,绑定列标题(而不是直接设置它)可能会变得很麻烦,因为 DataGrid 列不会继承父级的 DataContext,但这里提供了一种解决方法: http://blogs.infragistics.com/blogs/josh_smith/archive /2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx

Not a whole answer to your question, but WPF DataGrid isn't great at playing nice with a variable number of columns.

What you might be able to do is create an anonymous type dynamically (e.g., http://jacobcarpenter.wordpress.com/2008/03/13/dictionary-to-anonymous-type/), and turn on auto generate columns so it does so through reflection, otherwise you'll have to define your columns in code.

Note also that binding the column header (as opposed to setting it directly) could get hairy because DataGrid columns don't inherit the parent's DataContext, but there's a workaround presented here: http://blogs.infragistics.com/blogs/josh_smith/archive/2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx.

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