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!