C#C
C#2y ago
2 replies
Nacho Man Randy Cabbage

Binding Dictionary to DataGrid (WPF)

I have multiple lists of objects of the same type that contain a dictionary property and I want to bind a datagrid column header to the key, and the cell values to the dictionary's value. Example of the object:

public class MyObject
{
    public Dictionary<string, string> Data { get; } // key would be a column header, value would be cell value
}


Now, in each list, the keys themselves will remain the same for each object's dictionary, but could change between lists, so I can't have static column headers. There is no editing in the grid, although I am gonna allow the hiding of columns and filtering.

Not sure the best way to go about this. If it was static keys I could just create an object to represent the data in the dictionary and make an observable collection of that.
Was this page helpful?