0

I need to create a grid layout control in a user control. I'm having trouble because the columns aren't known in advance, and come in from the data that I bind to. The shape of the data looks like this ...

public class SummaryRow
{
    public string Name { get; set; }
    public GridCellValue[] Values { get; set; }

    public class GridCellValue
    {
        public string Value { get; }
        public string Status { get; }

        public GridCellValue(string value, string status)
        {
            Value = value;
            Status = status;
        }
    }
}

So there's an instance of this class per row in the grid. I can change the shape of this class if required if there's a way of structuring this to make it easier.

The first column will the Name property, and is just a textblock. The rest of the columns need to be a template (the same template) as I need to customise them based on the Status property. Except for the first column, they're all the same template- just bound to different elements of the Values array. I also have another string array in the viewmodel with the names of the headers.

I don't mind if this is a Grid, ItemsControl, DataGrid or combination - but it shouldn't look like a "data grid" (ie. spreadsheet ;)).

I've tried this solution, but that didn't add new columns to the datatable - but just showed a misaligned grid in a single datagrid column.

When it comes down to it, I have no objections to programatically adding the columns in the code behind. I just don't know how to set up the binding for this so that each column refers to an item in the Values array in the model.

Does anyone have any ideas? It felt like such a simple problem too!

Dan
  • 5,692
  • 3
  • 35
  • 66
  • See here: https://stackoverflow.com/a/6997848/1136211 – Clemens Aug 29 '18 at 20:05
  • I came across that blog post earlier (but not via that SO post). I tried this, but couldn't get it to work - I'll give it another go tomorrow. Also, whilst that helps with the column definitions - I still don't know how to databind to the array so the first column is one style (just text), but the dynamic columns are custom styled - each databound to a different array item (albeit the same template). – Dan Aug 29 '18 at 20:14

0 Answers0