简体   繁体   中英

.NET 4.0 WPF, DataGrid with Row and column headers

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!

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 (eg, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM